使用HtmlPlugin从一个子目录为webpack构build资源

我目前使用WebpackHtmlPlugin来简化我的index.html入口点,但是我的主要问题是index.html与所有其他资源(即publicPath所指向的任何地方)处于同一级别。

我想有一个文件夹中提供的index.html和webpack在子文件夹中生成的所有资产。 像这样的东西

index.html build/ bundle.js 1.bundle.js 2.bundle.js 

有没有什么办法可以达到这个目的,而不会违背webpack手动映射每个资产,并将publicPath设置为root?

您可以使用CopyWebpackPlugin与HTMLWebpackPlugin一起…

 plugins: [ new HtmlWebpackPlugin({ filename: "index.html", template: "index.html", inject: false }), new CopyWebpackPlugin([ { from: 'from/directory/**/*', to: '/absolute/path' }, ]) ], 

请参阅https://www.npmjs.com/package/copy-webpack-plugin中的参考资料