vueconfigjs 设置打包js css 名称
可以通过设置 output 中的 filename 和 chunkFilename 属性来设置打包后的 js 文件名,以及通过 mini-css-extract-plugin 插件来设置打包后的 css 文件名。
示例代码:
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
// ...
output: {
filename: 'js/[name].[contenthash].js', // 文件名添加 contenthash,避免浏览器缓存
chunkFilename: 'js/[name].[contenthash].js',
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/[name].[contenthash].css', // 文件名添加 contenthash,避免浏览器缓存
chunkFilename: 'css/[name].[contenthash].css',
}),
],
};
在上面的示例中,js 和 css 文件都被放在了 js 和 css 文件夹中,并且文件名中添加了 contenthash,以避免浏览器缓存。
其中,[name] 表示模块的名称,[contenthash] 表示根据文件内容生成的 hash 值。如果只是在开发环境中使用,可以将 contenthash 改为 hash,这样每次打包都会生成新的文件名
原文地址: https://www.cveoy.top/t/topic/eJOe 著作权归作者所有。请勿转载和采集!