I am trying to get multiple entrypoints working with webpackDevServer.
One entrypoint requires my entire node_modules folder. The other requires only a single file, with a single console.log in it (the entrypoint file).
For some reason, my single file with a single console.log won't run. See this question as well.
I was testing this setup in WebpackDevServer, so I suspected that all files needed at least WebpackDevServer to function, maybe. So, I changed my optimization.splitChunks
to look like this, based off the example on the webpack docs:
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all'
},
vendor: {
test: /[\\/]node_modules[\\/](webpack|webpack-dev-server)[\\/]/,
name: 'webpack',
chunks: 'all',
}
}
},
},
I expect there to be a "vendor" bundle and a "webpack" bundle. There is only "vendor" (and my entrypoints):
app.js 6.92 MiB app [emitted] app
resetPassword.js 35.2 KiB resetPassword [emitted] resetPassword
vendor.js 14.4 MiB vendor [emitted] vendor
How can I get webpack-dev-server
into its own bundle, which I can then include into HtmlWebpackPlugin, to test to see if that (or other node_modules) are what's needed to run my console.log
?
Webpack config
module.exports = {
entry: {
app: './public/js/ide.js',
resetPassword: './public/js/reset_password.js'
},
output: {
path: path.resolve(__dirname, '../build'),
filename: '[name].js',
publicPath: '/'
},
...
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all'
},
vendor: {
test: /[\\/]node_modules[\\/](webpack|webpack-dev-server)[\\/]/,
name: 'webpack',
chunks: 'all',
}
}
},
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'public/html/ide.html',
inject: true,
chunks: ['app', 'vendor']
}),
new HtmlWebpackPlugin({
filename: 'reset_password.html',
template: 'public/html/reset_password.html',
inject: true,
chunks: ['resetPassword'] // this does not work
//chunks: ['resetPassword', 'vendor'] //this works
}),
],
}
reset_password.js
console.log('hello')
webpack dev server config
devServer: {
clientLogLevel: 'warning',
historyApiFallback: true,
hot: true,
compress: true,
host: HOST,
port: PORT,
open: config.dev.autoOpenBrowser,
overlay: false,
publicPath: '/',
contentBase: [
path.join(__dirname, "../../public"),
path.join(__dirname, "../../public/js")],
watchOptions: {
poll: config.dev.poll,
},
disableHostCheck: true,
https: true,
noInfo: false,
},