-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
141 lines (140 loc) · 3.79 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
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
/*
* @Author: astar
* @Date: 2021-02-23 10:16:42
* @LastEditors: astar
* @LastEditTime: 2022-01-30 18:40:45
* @Description: webpack配置
* @FilePath: \vue-chat\vue.config.js
*/
const path = require('path');
const resolve = (dir) => path.join(__dirname, dir);
const judgeEnv = env => process.env.NODE_ENV === env;
const IS_DEVELOPMENT = judgeEnv('development');
const IS_PRODUCTION = judgeEnv('production');
const PrerenderSPAPlugin = require('prerender-spa-plugin');
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer;
const publicPath = IS_PRODUCTION ? '/chat/' : '/';
module.exports = {
publicPath,
outputDir: path.join(__dirname, 'dist', publicPath),
lintOnSave: IS_DEVELOPMENT,
productionSourceMap: false,
devServer: {
port: 2000,
open: false,
// https: true,
proxy: {
'/test-proxy': {
target: 'http://localhost:3000',
pathRewrite: {
'^/test-proxy': ''
}
}
}
},
pwa: {
iconPath: {
favicon32: 'img/icons/icon.png',
favicon16: 'img/icons/icon.png',
appleTouchIcon: 'img/icons/icon.png',
maskIcon: 'img/icons/icon.png',
msTileImage: 'img/icons/icon.png'
},
workboxOptions: {
// https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin
skipWaiting: true, // 是否跳过waiting状态,激活sw
clientsClaim: true, // 通知让新的sw立即在页面上取得控制权
importWorkboxFrom: 'local',
importsDirectory: 'js',
navigateFallback: '/',
navigateFallbackBlacklist: [/\/api\//]
}
},
css: {
loaderOptions: {
postcss: {
plugins: [
require('postcss-pxtorem')({
rootValue: 100, // 换算的基数
propList: ['*']
}),
]
}
}
},
configureWebpack: {
externals: {},
plugins: IS_PRODUCTION ? [new PrerenderSPAPlugin({
staticDir: path.join(__dirname, 'dist'),
outputDir: path.join(__dirname, 'dist', publicPath),
indexPath: path.join(__dirname, 'dist', publicPath, '/index.html'),
routes: ['/login', '/register'],
renderer: new Renderer({
inject: {
foo: 'bar'
},
renderAfterDocumentEvent: 'render-event',
args: ['--no-sandbox', '--disable-setuid-sandbox']
})
})
] : []
},
chainWebpack (config) {
// IS_PRODUCTION && config.module
// .rule('images')
// .test(/\.(gif|png|jpe?g|svg)$/i)
// .use('image-webpack-loader')
// .loader('image-webpack-loader')
// .options({
// mozjpeg: {
// progressive: true,
// },
// optipng: {
// enabled: false,
// },
// pngquant: {
// quality: [0.65, 0.90],
// speed: 4
// },
// gifsicle: {
// interlaced: false,
// },
// webp: {
// quality: 75
// }
// })
// .end()
// 配置svgIcons,https://juejin.cn/post/6844903517564436493#heading-0
config.module
.rule('svg')
.exclude.add(resolve('src/icons'))
.end()
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('src/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
.end()
config.module
.rule('vue')
.test(/\.vue$/)
.use('vue-inline-px-to-rem')
.loader('vue-inline-px-to-rem')
.options({
rootValue: 100
})
.end()
config
.when(process.env.VUE_APP_OPEN_ANALYZER, config => {
config
.plugin('webpack-bundle-analyzer')
.use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
.end()
})
}
}