Babel is a few modular packages, the core functionality is in the NPM package that becomes babel-core, but Webpack integrates them together, but for each function and extension you need, you need to install a separate package (the most used is parsing ES6 Grammar of the babel-preset-es2015 package and parsing JSX of the babel-preset-react package)
Install command:npm install--save-dev babel-core babel-loader babel-preset-es2015 babel-preset-react
then write in the config entry for webpack.config.js:
{
test:/\.js$/,
Exclude:/node_modules/,
Loader: ' Babel ',//In the Webpack module section of the loaders configuration can be
query:{
presets:[' es2015 ', ' react ']
}
}
and add ES6 syntax to the work.js.
First sign out of the configuration item try
Then look at the syntax in the Webpack.js after the completion of NPM start :
As you can see, there is no conversion
Open index.html with Chrome browser, still can pop 7, because the latest Google browser support ES6 most of the syntax
And then cancel the notes in Webpack.config.js.
run the command again : NPM start
then take a look at the compiler-completed Webpack.js's syntax for this code to change
It turns out to be a familiar grammar.
Open index.html again , still pop up 7
can also be installed React, the command is NPM install--save React react-dom
Webpack Study notes Five