The following describes how to use webpack with babel to convert es6 to an ultra-simple instance of es5 and webpackes5.

Source: Internet
Author: User

The following describes how to use webpack with babel to convert es6 to an ultra-simple instance of es5 and webpackes5.

Today, I got started with webpack. The first time I used webpack for transcoding, it turned out to be a bit confusing. Haha.

The process is attached below

Create folders and initialize them. First, install webpack globally.

npm install webpack --save-dev 

Then install babel

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

Execute the installation in the current folder, and then create two folders: src as the source folder and bin to save the list of generated folders.

Create an app. js file in the src folder and write es6 code that is not fully supported by the browser.

let a = 111; let b = 222; var xxx = (c,d) => c*d; console.log(xxx(a,b)); 

Create a file named webpack. config. js in the root directory.

module.exports = {   entry: './src/app.js',   output: {     path: './bin',     filename: 'app.bundle.js',   },   module: {     loaders: [{       test: /\.js$/,       exclude: /node_modules/,       loader: 'babel-loader'     }]   } } 

Then create a file called by babel named. babelrc.

Write in

{ "presets": [ "es2015" ] } 

Then open cmd in the current directory,

Run the webpack command.

If a green image is displayed, it indicates the operation is successful.

Go to the bin directory and find app. bundle. js. The code below is found.

function(module, exports) {  "use strict";  var a = 111; var b = 222; var xxx = function xxx(c, d) {  return c * d; }; console.log(xxx(a, b)); 

Proves transcoding successful ~~~~

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

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.