-
Notifications
You must be signed in to change notification settings - Fork 272
/
vue.config.js
78 lines (73 loc) · 2.39 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
const path = require('path');
const webpack = require('webpack');
const SentryPlugin = require('@sentry/webpack-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const OfflinePackagePlugin = require('offline-package-webpack-plugin');
const version = require('./package.json').version;
const LocalConfig = require('./src/config.json');
const modifyVars = require('./modify-vars');
const NODE_ENV = process.env.NODE_ENV || 'development';
const IS_PRO = NODE_ENV === 'production';
const commonPlugins = [
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(version)
})
];
module.exports = {
publicPath: IS_PRO ? './' : '/',
productionSourceMap: IS_PRO,
css: {
extract: false,
loaderOptions: {
less: {
modifyVars
}
}
},
configureWebpack: () => {
if (IS_PRO) {
const productionPlugins = [new LodashModuleReplacementPlugin()];
if (LocalConfig.SentryEnabled && LocalConfig.SentryPluginEnabled) {
productionPlugins.push(
new SentryPlugin({
release: version, //发布的版本
include: path.join(__dirname, './dist/js'), //需要上传到sentry服务器的资源目录,会自动匹配 js 以及 map 文件
urlPrefix: '~/mobile-web-best-practice/js', //线上对应的 url 资源的相对路径
ignore: ['node_modules'] //忽略文件目录, 当然我们在 inlcude 中制定了文件路径,这个忽略目录可以不加
})
);
}
if (LocalConfig.OfflinePackageEnabled) {
productionPlugins.push(
new OfflinePackagePlugin({
packageNameKey: 'packageId',
packageNameValue: 'main',
version: 1,
baseUrl: 'https://mcuking.github.io/mobile-web-best-practice/',
fileTypes: ['js', 'css', 'png']
})
);
}
return {
plugins: [...commonPlugins, ...productionPlugins],
externals: {
// key 是给 import 的时候用的,value 表示的是如何在 global 中访问到该对象
vue: 'Vue',
vuex: 'Vuex',
'vue-router': 'VueRouter',
mockjs: 'Mock',
moment: 'moment',
hammerjs: 'Hammer'
}
};
} else {
return {
plugins: [...commonPlugins]
};
}
},
devServer: {
port: 8088, //配置端口
open: true //自动开启浏览器
}
};