-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvue.config.js
61 lines (58 loc) · 1.88 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
const path = require('path')
const fs = require('fs')
const argv = require('minimist')(process.argv.slice(2))
const { InjectManifest } = require('workbox-webpack-plugin')
const webpack = require('webpack')
const isDev = process.env.NODE_ENV === 'development'
const srcFiles = fs.readdirSync(path.resolve(__dirname, 'src/'))
// 项目名称
const projectName = path.resolve(__dirname).split(path.sep).pop()
// 页面片路径
const indexPath = srcFiles.find(file => path.extname(file) === '.html')
// 入口路径 (相对路径)
const entryPath = './src/main.js'
function getVersion () {
let d = new Date()
return '' + d.getFullYear() + d.getMonth() + 1 + d.getDate() + d.getHours() + d.getMinutes() + d.getSeconds()
}
module.exports = {
outputDir: 'dist/',
indexPath: indexPath,
publicPath: `${projectName}/`,
lintOnSave: process.env.NODE_ENV !== 'production',
runtimeCompiler: true,
productionSourceMap: !!argv.sourceMap,
crossorigin: 'anonymous',
chainWebpack: config => {
config.plugin('html')
.tap(args => {
args[0].minify = false
args[0].filename = indexPath
args[0].template = path.join(__dirname, `src/${indexPath}`)
return args
})
if (isDev) {
config.plugins.delete('preload')
config.plugins.delete('prefetch')
}
},
configureWebpack: config => {
config.entry.app[0] = entryPath
if (isDev) {
config.output.filename = 'js/[name].js'
config.output.chunkFilename = 'js/[name].js'
}
config.plugins.push(
new InjectManifest({
swSrc: './src/util/service-worker.js',
importsDirectory: 'js',
importWorkboxFrom: 'disabled', // 不使用谷歌workerbox的cdn
exclude: [/\.map$/, /^manifest.*\.js$/, /\.html$/]
}),
new webpack.DefinePlugin({
__SW_VERSION__: getVersion(),
__PROJECT_NAME__: JSON.stringify(projectName)
})
)
}
}