prod env 中的 Symfony 5 和 webpack encore:避免在构建文件名中使用哈希字符串

问题描述

当我运行命令 yarn build 时,会在 public/build 目录中创建一些文件,生成的文件会获得一个包含随机哈希字符串的新文件名:

enter image description here

对于文件主题/浅色和主题/深色,我需要在运行 yarn build 时自动删除随机哈希字符串,我想保留原始文件名。我的意思是,目前该命令生成这些文件:

  • public/build/themes/light.3ac94fb2.css
  • public/build/themes/dark.064ff2f6.css

相反,我想要:

  • public/build/themes/light.css
  • public/build/themes/dark.css

是否可以自动执行此操作?

解决方法

如果你不介意文件两次,一个有哈希,一个没有,那么 copyFiles 插件可能是你要走的路:

这项工作在 webpack.config.jsEncore 配置中添加如下内容:

Encore
    // Your usual config comes here

    .copyFiles([
        {
            from: './assets/themes/light.css',// or wherever the file lives in the assets folder
            to: 'public/build/themes/light.css'
        },{
            from: './assets/themes/dark.css',// or wherever the file lives in the assets folder
            to: 'public/build/themes/dark.css'
        }
    ])
;

注意:未经测试 - 在此处找到更多解释:https://symfonycasts.com/screencast/webpack-encore/copy-files

还有一个 configureFilenames 函数,但我不确定您是否能够将条件放入其中。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...