如何解决prod env 中的 Symfony 5 和 webpack encore:避免在构建文件名中使用哈希字符串
当我运行命令 yarn build
时,会在 public/build
目录中创建一些文件,生成的文件会获得一个包含随机哈希字符串的新文件名:
对于仅文件主题/浅色和主题/深色,我需要在运行 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.js 的 Encore
配置中添加如下内容:
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
函数,但我不确定您是否能够将条件放入其中。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。