-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvue.config.example.js
144 lines (139 loc) · 3.87 KB
/
vue.config.example.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* @description: 案例的打包配置
* @Author: xing.heng
*/
'use strict'
const path = require('path')
const CompressionPlugin = require('compression-webpack-plugin')
const webpack = require('webpack')
function resolve (dir) {
return path.join(__dirname, dir)
}
const publicPath =
process.env.VUE_APP_HISTORY === 'y' ? process.env.VUE_APP_BASE + '/' : ''
const JS_CDN = [
publicPath + 'static/libs/vuex/vuex.min.js',
publicPath + 'static/libs/vue-router/vue-router.min.js'
]
const CSS_CDN = []
const cdn = {
css: CSS_CDN,
js: JS_CDN
}
const port = process.env.port || process.env.npm_config_port || 7521 // dev port
const plugins = [
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
'window.jQuery': 'jquery'
})
]
module.exports = {
parallel: require('os').cpus().length > 1,
pages: {
index: {
entry: ['example/main.js'],
template: 'public/index.html',
filename: 'index.html',
chunks: 'all'
}
},
publicPath:
process.env.VUE_APP_HISTORY === 'y' ? process.env.VUE_APP_BASE : './',
outputDir: 'gc-starter-bigscreen-ui',
assetsDir: 'static',
lintOnSave: false,
productionSourceMap: false,
runtimeCompiler: true,
devServer: {
hot: true,
port: port,
client: {
overlay: false
}
},
configureWebpack: config => {
// provide the app's title in webpack's name field, so that
// it can be accessed in index.html to inject the correct title.
// name: name,
config.cache = {
type: 'filesystem',
cacheDirectory: path.resolve(__dirname, '.cache')
}
Object.assign(config.resolve, {
alias: {
'@': resolve('example'),
vue$: 'vue/dist/vue.common',
// 大屏工程路径别名
packages: resolve('packages'),
'gc-starter-bigscreen-ui': resolve('packages/index.js')
},
fallback: {
path: false,
fs: false
}
})
// 如果是开发模式,忽略一些组件打包,采用cdn
config.externals =
process.env.NODE_ENV === 'production'
? {
'vue-router': 'VueRouter',
vuex: 'Vuex'
}
: {}
if (process.env.NODE_ENV === 'production') {
return {
plugins: [
new CompressionPlugin({
cache: true, // 开启缓存
test: /\.js$|\.html$|\.css$|\.jpg$|\.jpeg$|\.png/, // 需要压缩的文件类型
threshold: 10240, // 归档需要进行压缩的文件大小最小值,10K以上的进行压缩
deleteOriginalAssets: false // 是否删除原文件
}),
...plugins
]
}
} else {
return {
plugins: [
...plugins
]
}
}
},
chainWebpack: config => {
if (process.env.NODE_ENV === 'production') {
config.plugin('html-index').tap(args => {
// html中添加cdn
args[0].cdn = cdn
// 修复 Lazy loading routes Error
args[0].chunksSortMode = 'none'
return args
})
}
config.plugins.delete('prefetch-index') // 关闭prefetch
config.module
.rule('svg')
.exclude.add(resolve('packages/assets/images/dataSourceIcon/svg'))
.add(resolve('packages/assets/images/pageIcon/svg'))
.add(resolve('packages/assets/images/bigScreenIcon/svg'))
.add(resolve('packages/Svgs/svg'))
.end()
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('packages/assets/images/dataSourceIcon/svg'))
.add(resolve('packages/assets/images/pageIcon/svg'))
.add(resolve('packages/assets/images/bigScreenIcon/svg'))
.add(resolve('packages/Svgs/svg'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
.end()
},
// 在这里配置需要对node_modules中需要进行语法转义的依赖
transpileDependencies: []
}