I would like to use tree shaking feature seems we don't need to install babel-preset-es2015-webpack
. We still can use babel-preset-es2015
and set the modules flag to false for es2015
preset. I changed my webpack configuration as shown below which results in "Unexpected token import" error on import line in my react components.
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: [['es2015', {modules: false}], 'react']
}
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader!sass-loader")
}
]
}
I also tried to set the presets as
['es2015', 'react', {modules: false}]
Then I got different error on console:
Module build failed: ReferenceError: [BABEL] C:\FE-Proj-Templates\webpack\main.js: Using removed Babel 5 option: foreign.modules - Use the corresponding module transform plugin in the `plugins` option. Check out http://babeljs.io/docs/plugins/#modules
How can I set the preset es2015
with modules flag false and also use React preset?
In Node. js, for example, you can conditionally run require with a variable to load a random script. Webpack can't possibly know all of your imports and exports at build time, so it will attempt to tree shake a handful of constructs and bail as soon as things get too dynamic.
If you're using modern tooling, such as webpack, create-react-app and similars, you already have tree shaking set up.
It's updated and works
presets: [['es2015', {modules: false}], 'react']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With