ES6 layman -6 ES 6 modules -2.babel webpack parcel




https://babeljs.io/


copied to the command line

prompt a warning. This file is missing package.json

npm the init -t

LS generated package.json then saw this document.

Then go babel installed

after the installation is complete, one more node_module directory. babel on the node_module installed in the directory inside.


Use
together with the code in the file package.json


prompt error. From src to the lib directory, that is, you need both src and lib directories

, respectively, to create two directories are

all modular code in src below.
The following code motion all js file format to the src folder

are files in js src.

RUN Build execution npm

main.js into this. Then execute npm run build

Also you need to implement Part IV



Execute this command line

to create something of a .babelrc.

Inside write the code

to re-Build

main.js the lib changes

modify the index.html file. Inside main.js files under lib with.

An error require no definition.

The question now is, he became the import require. But it does not require. In nodejs which is running in the browser is not running

With webpack



webpack 100 times more than hard Babel



 

parcel

webpack too hard, so he invented the parcel was





executed npm install -g parcel-bundler

delete lib file members

to src following js files are moved out.

Delete src directory

of the current list of root directory are listed.

index.html or referenced within this document is main.js.

parcel index.html


View page

run success.


Page load js file


main.js actually two sentences






automatically packed js files saved


End

 

Guess you like

Origin www.cnblogs.com/wangjunwei/p/11831379.html