|
|
|
@ -17,6 +17,9 @@ const postcss = px2rem({
|
|
|
|
|
// 基准大小 baseSize,需要和rem.js中相同
|
|
|
|
|
remUnit: 14,
|
|
|
|
|
});
|
|
|
|
|
// 创建hash
|
|
|
|
|
const hash =
|
|
|
|
|
"v" + require("./package.json").version + "." + new Date().getTime();
|
|
|
|
|
|
|
|
|
|
// vue.config.js 配置说明
|
|
|
|
|
//官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions
|
|
|
|
@ -69,6 +72,12 @@ module.exports = {
|
|
|
|
|
plugins: [postcss],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// 给css文件添加hash
|
|
|
|
|
extract: {
|
|
|
|
|
// 打包后css文件名称添加时间戳
|
|
|
|
|
filename: `css/[name].${hash}.css`,
|
|
|
|
|
chunkFilename: `css/[name].${hash}.css?hash=${hash}`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
configureWebpack: {
|
|
|
|
|
name: name,
|
|
|
|
@ -87,6 +96,10 @@ module.exports = {
|
|
|
|
|
minRatio: 0.8, // 压缩率小于1才会压缩
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
output: {
|
|
|
|
|
filename: `js/[name].${hash}.js`,
|
|
|
|
|
chunkFilename: `js/[name].${hash}.js?hash=${hash}`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
chainWebpack(config) {
|
|
|
|
|
config.plugins.delete("preload"); // TODO: need test
|
|
|
|
@ -105,6 +118,24 @@ module.exports = {
|
|
|
|
|
symbolId: "icon-[name]",
|
|
|
|
|
})
|
|
|
|
|
.end();
|
|
|
|
|
// 给图片的文件名添加hash
|
|
|
|
|
config.module
|
|
|
|
|
.rule("images")
|
|
|
|
|
.use("url-loader")
|
|
|
|
|
.tap((options) => {
|
|
|
|
|
return {
|
|
|
|
|
//4kb以下图片会被编译成base64 嵌入到css中(可以减少资源请求数量)
|
|
|
|
|
//4kb以上url-loader表现行为等同于file-loader,会走文件资源请求
|
|
|
|
|
limit: 4096,
|
|
|
|
|
// test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
|
|
|
|
|
fallback: {
|
|
|
|
|
loader: "file-loader",
|
|
|
|
|
options: {
|
|
|
|
|
name: `img/[name].${hash}.[ext]`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
config.when(process.env.NODE_ENV !== "development", (config) => {
|
|
|
|
|
config
|
|
|
|
|