-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
79 lines (75 loc) · 2.42 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const path = require("path")
const webpack = require("webpack")
const env = process.env.NODE_ENV
const devProxy = ["/api"] // 代理
const DEV_URI = "http://localhost:3000"
const PRO_URI = "http://192.168.1.39:3000"
const target = env === "production" ? PRO_URI : DEV_URI
let proxyObj = {};
devProxy.forEach(value => {
proxyObj[value] = {
target: target,
changeOrigin: true,
pathRewrite: {
[`^${value}`]: ""
}
};
});
module.exports = {
// baseUrl: env === "production" ? "/dist/" : "/",
outputDir: "dist",
assetsDir: "assets",
// 生成的静态资源在它们的文件名中包含了 hash
filenameHashing: true,
// 加速生产环境构建
productionSourceMap: false,
pages: {
index: {
entry: "src/main.ts",
template: "public/index.html",
filename: "index.html"
}
},
lintOnSave: env !== "production", // 是否在开发环境下通过eslint-loader在每次保存时lint代码。这个值在@vue/cli-plugin-eslint被安装之后生效
devServer: {
publicPath: env === "production" ? "/dist/" : "/",
hot: true,
contentBase: path.join(__dirname, "dist"),
hotOnly: false,
disableHostCheck: true,
proxy: proxyObj
},
chainWebpack: config => {
// 移除 prefetch 插件
config.plugins.delete("prefetch")
config.plugin("fork-ts-checker")
config.module.rule("ts").use("ts-loader", "babel-loader")
},
css: {
modules: true,
loaderOptions: {
// 给 sass-loader 传递选项
sass: {
// 全局scss文件导入
// 所以这里假设你有 `src/variables.scss` 这个文件
data: `@import "~vue-material/dist/theme/engine.scss";
@import "~vue-material/dist/theme/default.css";
@import "~vue-material/dist/components/index.css";
@import "@/assets/common.scss";`
},
// 生成的 CSS Modules 模块的类名
css: {
localIdentName: "[name]-[hash]",
camelCase: "only"
}
}
},
// 配置本地webpack,然后自动merge到webpack
configureWebpack: config => {
if (env === "production") {
// 为生产环境修改配置...
} else {
// 为开发环境修改配置...
}
}
}