I am trying to use react loadable and dynamic import to split code to multiple bundles. The split process works very well. However, when I try to use the magic comment webpackChunkName
to let Webpack customize the bundle names, it always name my bundles like 0.bundle.js 1.bundle.js ....
I used chunkFilename: '[name].bundle.js'
in my webpack.config.js
and also explicitly put "comments: true
" in my .babelrc
After a whole day's research, I really feel frustrated. Really appreciate if someone has a clue.
Here is my configuration
webpack.config.js
entry: [
'react-hot-loader/patch',
'./app/index.js'
],
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
publicPath: '/'
},
.babelrc
{
"presets": [
["env", {"modules": false}],
"react"
],
"plugins": ["transform-class-properties", "transform-object-rest-spread", "react-hot-loader/babel", "syntax-dynamic-import", "dynamic-import-webpack"],
"env": {
"test": {
"presets": [
"env",
"react"
],
"plugins": ["transform-class-properties", "transform-object-rest-spread", "dynamic-import-webpack"]
}
},
"comments": true
}
Router file
const Login = Loadable({
loader: () => import(/* webpackChunkName: 'LoginContainer' */ './containers/LoginContainer'),
loading: LoadingAnimation,
});
The building result:
Am I missing anything here?