forked from dyq086/wepy-mall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wepy.config.js
executable file
·94 lines (86 loc) · 2.06 KB
/
wepy.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
var prod = process.env.NODE_ENV === 'production'
var path = require('path');
var fs = require('fs');
module.exports = {
wpyExt: '.wpy',
eslint: false,
compilers: {
less: {
compress: true
},
babel: {
sourceMap: true,
presets: [
'es2015',
'stage-1'
],
plugins: [
'transform-decorators-legacy',
'transform-export-extensions',
'syntax-export-extensions'
]
}
},
plugins: {}
}
if (prod) {
//删除目标文件
deleteTarget("dist");
delete module.exports.compilers.babel.sourcesMap;
// 压缩sass
// module.exports.compilers['sass'] = { outputStyle: 'compressed' }
// 压缩less
module.exports.compilers['less'] = { compress: true }
// 压缩js
module.exports.plugins = {
uglifyjs: {
filter: /\.js$/,
config: {}
},
imagemin: {
filter: /\.(jpg|png|jpeg)$/,
config: {
jpg: {
quality: 80
},
png: {
quality: 80
}
}
}
}
}
// 删除目标文件夹或文件
function deleteTarget(fileUrl) {
// 如果当前url不存在,则退出
if (!fs.existsSync(fileUrl)) return;
// 当前文件为文件夹时
if (fs.statSync(fileUrl).isDirectory()) {
var files = fs.readdirSync(fileUrl);
var len = files.length,
removeNumber = 0;
if (len > 0) {
files.forEach(function(file) {
removeNumber++;
var stats = fs.statSync(fileUrl + '/' + file);
var url = fileUrl + '/' + file;
if (fs.statSync(url).isDirectory()) {
deleteTarget(url);
} else {
fs.unlinkSync(url);
}
});
if (removeNumber === len) {
// 删除当前文件夹下的所有文件后,删除当前空文件夹(注:所有的都采用同步删除)
fs.rmdirSync(fileUrl);
console.log('删除文件夹' + fileUrl + '成功');
}
} else {
fs.rmdirSync(fileUrl)
}
} else {
// 当前文件为文件时
fs.unlinkSync(fileUrl);
console.log('删除文件' + fileUrl + '成功');
}
}