【发布时间】:2018-09-24 22:15:54
【问题描述】:
我正在尝试让多个入口点与 webpackDevServer 一起工作。
一个入口点需要我的整个 node_modules 文件夹。另一个只需要一个文件,其中包含一个 console.log(入口点文件)。
由于某种原因,我的带有单个 console.log 的单个文件将无法运行。 See this question as well.
我在 WebpackDevServer 中测试这个设置,所以我怀疑所有文件至少需要 WebpackDevServer 才能运行,也许。所以,我把我的optimization.splitChunks改成这样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',
}
}
},
},
我希望会有一个“供应商”包和一个“webpack”包。只有“供应商”(和我的入口点):
app.js 6.92 MiB app [emitted] app
resetPassword.js 35.2 KiB resetPassword [emitted] resetPassword
vendor.js 14.4 MiB vendor [emitted] vendor
我怎样才能将webpack-dev-server 放入它自己的包中,然后我可以将其包含到 HtmlWebpackPlugin 中,以测试它(或其他 node_modules)是否是运行我的console.log 所需要的?
Webpack 配置
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 开发服务器配置
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,
},
【问题讨论】:
标签: javascript webpack webpack-dev-server html-webpack-plugin