Webpack 配置 - 在 mini-css-extract-plugin 中检索 [name] 作为变量

问题描述

我正在尝试根据我的 JS 和 CSS 文件的 [name] 有条件地设置文件名。我的 webpack 设置看起来像下面的代码。在输出文档 (https://webpack.js.org/configuration/output/#outputfilename) 中,它表明 [name] 可以通过“pathData.chunk.name”访问。我也想对 MiniCssExtractPlugin 中的 CSS 文件执行同样的操作,但无法找出 [name] 存储在哪个变量中。

有人能解释一下吗?

非常感谢! 珍娜

module.exports = {
  ...
  output: {
    filename: (pathData) => {
      return pathData.chunk.name === 'main' ? '[name].js' : '[name]/[name].js';
    },},...
  plugins: [
    ...
    new MiniCssExtractPlugin({
      filename: chunk.name ? '[name].css' : '[name].' + thisConfig['version'] + '.css',chunkFilename: '[id].css',}),]


解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...