-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
61 lines (56 loc) · 2.11 KB
/
vue.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const path = require("path");
const webpack = require("webpack");
const { defineConfig } = require("@vue/cli-service");
const WindiCSSWebpackPlugin = require("windicss-webpack-plugin");
const target = process.env.VUE_APP_TARGET || "";
module.exports = defineConfig({
// https://github.com/vuejs/vue-cli/issues/2754#issuecomment-493290698
runtimeCompiler: true,
transpileDependencies: true,
css: {
loaderOptions: {
scss: {
additionalData(source, loaderContext) {
const dataList = [
'@import "/src/assets/styles/element-variables.scss";',
'@import "/src/assets/styles/variables.scss";',
'@import "/src/assets/styles/mixin.scss";',
];
const data = dataList.join("\n");
const { resourcePath, rootContext } = loaderContext;
console.log("resourcePath:", resourcePath);
console.log("rootContext:", rootContext);
let relativePath = path.relative(rootContext, resourcePath);
// 兼容 windows
relativePath = relativePath.split(path.sep).join("/");
// 排除 element/index 因为用到了 @forward,这个前面不能插入其他代码
if (relativePath.endsWith("variables.scss")) {
return source;
// 所有以 variables.scss 结尾的文件讲不会再重新导入 additionalData
// 排除两个 variables.scss
} else {
// 否则,将默认配置的 scss 文件加入到源文件内容中
return `${data} ${source}`;
}
},
},
},
},
configureWebpack: {
plugins: [
// 差异化打包路径替换
// 目前仅限 router|views 两个目录下的与-EAP_TARGET结尾的文件
new webpack.NormalModuleReplacementPlugin(
/(\S*)\/(router|views|layout|url-info)\/(\S+)-EAP_TARGET\.([A-Za-z]+)$/,
(resource) => {
const eapTarget = target ? `-${target}` : "";
resource.request = resource.request.replace(
/-EAP_TARGET/,
`${eapTarget}`
);
}
),
new WindiCSSWebpackPlugin(),
],
},
});