Webpack ES6 Support Configuration

Source: Internet
Author: User

  1. Install Babel and The Presets:

    npm install --save-dev babel-core babel-preset-es2015
  2. Install babel-loader :

    npm install --save-dev babel-loader
  3. Configure Babel to use these presets by adding.babelrc

     { "presets": [ "es2015" ] }
  4. modify  webpack.config.js  to process all  . js  files using   babel-loader .

      module.exports = {entry: './src/app.js ', Output: {path: './bin ', filename: ' App.bund             Le.js ',}, module: {loaders: [{test:/\.js$/, exclude:/node_modules/, Loader: ' Babel-loader ',}]}}  

    We are excluding  Node_modules here because otherwise all external libraries would also go through Babel, slowing down compilation.

  5. Install the libraries want to use (in this example, JQuery):

    npm install --save jquery babel-polyfill

    We are using --save the instead --save-dev of this time, as these libraries'll be the used in runtime. We also use So, babel-polyfill ES2015 APIs is available in older browsers.

  6. Edit src/app.js :

     import ‘babel-polyfill‘; import cats from ‘./cats‘; import $ from ‘jquery‘; $(‘
  7. Bundle the modules using Webpack:

     webpack
  8. Add so this index.html app can be run:

    <!DOCTYPE html><body> <script src="bin/app.bundle.js"></script>

Webpack ES6 Support Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.