npm install --save-dev babel-core@6 babel-preset-env@1 babel-loader@7
npm install --save babel-polyfill@6
babel-core
: contains core functionality of the babel compilerbabel-preset-env
: babel preset takes care of converting the newer js code to current js codebabel-loader
: needed for webpack to load babel fileswebpack.config.js
:module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
}
test
: regexp that tests (for this example) all the files and selects only js
filesuse
: now that you selected all the js files, you specify that you want to use the babel-loader
on themexclude
: all other js files that live in the node_modules
folder will also have the babel-loader
applied to them, and that is unnecessary, so exlude files located in there.babelrc
into the root directory{
"preset": [
"env", {
"target": {
"browsers": [
"last 5 versions",
"ie >= 8"
]
}
}
]
}
npm install babel-polyfill@7 --save
webpack.config.js
: entry: ['babel-polyfill', './src/js/index.js'],