Using the Create Responsive app and ES6 dependencies

I wrote an npm package blokusthat uses ES6 syntax.

I used create-react-appto run a project web-blokusthat depends on blokus.

I can start npm startwithout errors and view my application web-blokusin my browser, and it has all the features of using the package blokus.

The problem is that I get a UglifyJS error on startup npm build.

static/js/main.8afd34e2.js from UglifyJs
SyntaxError: Name expected [./~/blokus/blokus/blokus.js:3,0]

It seems that there is a known situation where UglifyJS does not support ES6 dependencies (several related problematic issues here and here ). But I read these topics, as well as several others, and I was very confused about what was planned to update and what people do as workarounds.

So i wanted

1) confirm that create-react-appit will not work out of the box (after switching to npm build) if your application has any ES6 dependencies

2) ask what people are doing to fix / work around the problem (do I need to banish and replace something for UglifyJS?)

Since create-react-appES6 is now so popular, I assume that I either misunderstand the restriction, or the standard method for resolving this restriction is discussed and known.

+6
1

ES6 create-react-app .

npm ES6 - , , node.

, , ES6 src:

npm install --save-dev babel-core babel-cli babel-preset-latest

.babelrc

{
  "presets": ["latest"]
}

package.json

  "main": "./lib",
  "scripts": {
    "build": "babel src --out-dir lib"
  }

npm run build .


.gitignore 'lib' .npmignore, . .npmignore.

src ( lib, ).

+3

Source: https://habr.com/ru/post/1015923/


All Articles