-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
95 lines (91 loc) · 2.9 KB
/
index.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
const fs = require('fs')
const { createPage } = require('./libs/page')
function normalizeConfig(args) {
const config = {}
for (const key in args) {
// if (renamedArrayArgs[key]) {
// config[renamedArrayArgs[key]] = args[key].split(',')
// } else if (renamedArgs[key]) {
// config[renamedArgs[key]] = args[key]
// } else if (key !== '_') {
config[camelize(key)] = args[key]
// }
}
return config
}
function camelize(str) {
return str.replace(/-(\w)/g, (_, c) => c ? c.toUpperCase() : '')
}
module.exports = (api, projectOptions) => {
const isAndroid = process.env.PLATFORM_ENV === 'android'
api.chainWebpack(config => {
config.module
.rule('svg')
.use('file-loader')
.loader('file-loader')
.tap(options => {
// 修改它的选项...
options.name = 'imgage/[name].[hash:8].[ext]'
return options
})
const imagesRule = config.module.rule('images')
var ruleImageLoader = imagesRule
.use('@snicesoft/image-webpack-loader')
.loader('@snicesoft/image-webpack-loader')
if (isAndroid) {
ruleImageLoader.options({
bypassOnDebug: true,
webp: {
quality: 75
}
})
}
ruleImageLoader.end()
imagesRule
.use('url-loader')
.loader('url-loader')
.tap(options => {
options.name = `imgage/[name].[hash:8].${isAndroid ? 'webp' : '[ext]'}`
return options
})
.end()
})
api.registerCommand('ac', {
usage: 'vue-cli-service ac <command> [options]',
commands: {
'add [options] <page-name>': 'create new page'
},
options: {
'--type [type]': '指定页面模板 (默认:default)'
}
}, args => {
if (args._.length === 0) {
// help
return
}
const argsConfig = normalizeConfig(args)
const config = Object.assign({
type: 'default',
}, argsConfig)
const pagesPath = api.resolve('./src/pages')
const type = args._[0]
switch (type) {
case 'add':
let name = args._[1]
if (name) {
name = name.toLowerCase()
const newPageDir = `${pagesPath}/${name}`
if (fs.existsSync(newPageDir)) {
console.warn('page [' + name + '] exists.')
return
}
createPage(newPageDir, config.type, name)
} else {
console.error('please use [ac add `new_page`]')
}
break;
default:
break
}
})
}