Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 如何选择特定html页面将使用的捆绑包?_Webpack_Pug Loader - Fatal编程技术网

Webpack 如何选择特定html页面将使用的捆绑包?

Webpack 如何选择特定html页面将使用的捆绑包?,webpack,pug-loader,Webpack,Pug Loader,项目 我有一个项目,其中的网站视图是使用Pug编写的,然后编译成HTML index.pug-->index.html 因为我希望项目有多个页面,所以我也得到了这个: about.pug-->about.html 现在,每个页面都有条目,在webpack.config.js中: { 条目:{ 索引:['scripts/index.ts'], 关于:['scripts/about.ts'], } } 我不认为两者都有一个单独的包是好的,因为每个页面条目都有唯一的导入模块(也就是说:如果我知道我在

项目

我有一个项目,其中的网站视图是使用Pug编写的,然后编译成HTML

index.pug-->index.html

因为我希望项目有多个页面,所以我也得到了这个:

about.pug-->about.html

现在,每个页面都有条目,在
webpack.config.js
中:

{
条目:{
索引:['scripts/index.ts'],
关于:['scripts/about.ts'],
}
}
我不认为两者都有一个单独的包是好的,因为每个页面条目都有唯一的导入模块(也就是说:如果我知道我在说什么的话)

问题

生成HTML时,会在两个页面中自动注入两个bundle,这比我刚才解释的更糟糕

我怎么能告诉它注射我想要的包呢


ps:我试着手动将它们包括在
*.pug
文件中。虽然生成的bundle文件名有散列,但为了实现缓存破坏。

在写这个问题之前,我花了三个小时寻找解决方案

不过,在提交之后,我立即刷新了搜索页面并找到了解决方案

这是关于大块的

您将选项散列传递给
html网页包插件
,其中有一个名为“chunks”的属性。此属性可以采用字符串数组,其中包含所需条目的名称


{
插件:[
新HtmlWebpackPlugin({
模板:“views/index.pug”,
脚本加载:“延迟”,
文件名:“index.html”,
块:[
“索引”
]
}),
新HtmlWebpackPlugin({
模板:“views/about.pug”,
脚本加载:“延迟”,
文件名:“about.html”,
块:[
“关于”
]
}),
新的HtmlWebpackPugPlugin()
]
}
抱歉给你添麻烦了