JS modularity (four): ES6 specification

1: Initialize package.json

npm init

2: Install babel-preset-es2015 (in a production environment)

npm install babel-preset-es2015 --save-dev

3: Add a .babelrc file in the same level directory of package.json

  • And add the following content
{
    
    
    "presets": ["es2015"]
}

If you need to install babel globally:
npm install --global babel-cli

4: Convert ES6 to ES5

babel js/src -d js/build

5: Use browserify to package

  • Note: The packaged is ES5 file
browserify js/build/main.js -o js/dist/bundle.js

6: Introduce the bundle.js file

This article is a supplement to this article:

ES6—49: Modularization

Guess you like

Origin blog.csdn.net/sinat_41696687/article/details/115002518