vue.config.js
2 KB
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
const fs = require("fs");
const vinfopath = "./public/js/version.json";
const BuildInfo = require("./version.js");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
const CopyWebpackPlugin = require("copy-webpack-plugin") //引入插件
module.exports = {
productionSourceMap: false,
lintOnSave: false,
publicPath: process.env.NODE_ENV === "production" ? "./" : "/",
// ...
transpileDependencies: ['element-ui'], // 此段为增加配置选项
css: {
loaderOptions: {
sass: {
prependData: '@import "@/assets/scss/common.scss";'
}
}
},
configureWebpack: {
plugins: [
new CopyWebpackPlugin([ //打包时执行拷贝
{
from: __dirname + "/public/config/js/config.js",
to: __dirname + "/dist/config/js/config.js"
}
])
]
},
chainWebpack: config => {
// config.entry('main').add('babel-polyfill')
if (process.env.use_analyzer) {
// 分析
config
.plugin("webpack-bundle-analyzer")
.use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin);
}
if (process.env.NODE_ENV === "production") {
var verinfo = fs.openSync(vinfopath, "w+");
var options = { encoding: "UTF-8", mode: 438 /*=0666*/, flag: "w" };
fs.writeFileSync(verinfo, JSON.stringify(BuildInfo), options);
}
},
pluginOptions: {
// 第三方插件配置
},
devServer: {
proxy: {
"/api/dashboards": {
target: "http://192.168.9.133:5000", // 要访问的接口域名
// ws: true, // 是否启用websockets
changeOrigin: true, //开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,这样服务端和服务端进行数据的交互就不会有跨域问题
pathRewrite: {
"^/api": "" //这里理解成用'/api'代替target里面的地址,比如我要调用'http://40.00.100.100:3002/user/add',直接写'/api/user/add'即可
}
}
}
}
};