css - 具有单独构建的 Webpack 2 html 文件

标签 css iframe webpack bundle webpack-4

我想设置一个包含 2 个 html 文件的元素:index.htmliframe.html

index.html 应该注入(inject)来自 index.js 文件的包,但是对于 iframe.html 我想注入(inject)来自 iframe.js 文件中包含的依赖项的包。

我有一个用于 2 个入口点的 webpack(通用)配置:

entry: {
 app: Path.resolve(__dirname, '../src/scripts/index.js'),
 iframe: Path.resolve(__dirname, '../src/scripts/iframe.js')
},
output: {
  path: Path.join(__dirname, '../build'),
  filename: 'js/[name].js'
},

但似乎两个 html 文件都注入(inject)了完整的包 - 我该如何拆分它? (并确保 index.js 不会包含/共享 iframe.js 文件中的代码?)

最佳答案

感谢this thread我找到了解决方案:

new HtmlWebpackPlugin({
  filename: 'index.html',
  template: Path.resolve(__dirname, '../src/index.html'),
  chunks: ['app']
}),
new HtmlWebpackPlugin({
  filename: 'iframe.html',
  template: Path.resolve(__dirname, '../src/iframe.html'),
  chunks: ['iframe']
})

关于css - 具有单独构建的 Webpack 2 html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57987254/

相关文章:

macos - 热模块更换不适用于 Mac/Vagrant

jquery - Bootstrap 崩溃数据目标选择器失败

css - 骨架列在 Firefox 顶部添加奇怪的空间

jquery - 全屏 Iframe

javascript - Facebook Like 按钮如何工作?

javascript - CSS 不适用于 Webpacked 模块

javascript - 在多个 <select> 列表中换行文本

css - 用纯 CSS 隐藏一个元素的列表

html - 我如何拥有静态高度/宽度侧边栏和底部栏以及包含 iframe 的响应式主要内容区域?

javascript - 使用 webpack 将多个 ES6 类捆绑到一个文件中,以便在脚本标签中导入