forked from nicholaswan/jjb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
157 lines (138 loc) · 4.91 KB
/
gulpfile.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
145
146
147
148
149
150
151
152
153
154
155
156
157
const gulp = require('gulp');
const concat = require('gulp-concat');
const cleanCss = require('gulp-clean-css');
const watch = require('gulp-watch');
const replace = require('gulp-replace');
const preprocess = require('gulp-preprocess');
const Bundler = require('parcel-bundler');
const Path = require('path');
async function bundleBuild(fileName) {
let file = Path.join(__dirname, `./${fileName}`);
let options = {
outDir: './dist', // 将生成的文件放入输出目录下,默认为 dist
outFile: fileName, // 输出文件的名称
publicUrl: './', // 静态资源的 url ,默认为 dist
watch: false, // 是否需要监听文件并在发生改变时重新编译它们,默认为 process.env.NODE_ENV !== 'production'
cache: true, // 启用或禁用缓存,默认为 true
cacheDir: '.cache', // 存放缓存的目录,默认为 .cache
minify: (process.env.NODE_ENV === 'production'), // 压缩文件,当 时,会启用
target: 'browser', // 浏览器/node/electron, 默认为 browser
https: false, // 服务器文件使用 https 或者 http,默认为 false
logLevel: (process.env.NODE_ENV === 'production') ? 1 : 3, // 3 = 输出所有内容,2 = 输出警告和错误, 1 = 输出错误
sourceMaps: (process.env.NODE_ENV != 'production'),
hmrHostname: '', // 热模块重载的主机名,默认为 ''
detailedReport: true // 打印 bundles、资源、文件大小和使用时间的详细报告,默认为 false,只有在禁用监听状态时才打印报告
};
let bundler = new Bundler(file, options);
await bundler.bundle();
}
gulp.task('watch', function () {
// watch many files
watch([
'manifest.json', '*.html',
'static/*.js', 'static/style/*.css'
], function () {
gulp.start('default');
});
});
gulp.task('pack-priceChart', function () {
gulp.src([
'node_modules/weui.js/dist/weui.min.js',
'node_modules/@antv/g2/dist/g2.min.js',
'static/priceChart.js'
])
.pipe(concat('priceChart.js'))
.pipe(replace('{{version}}', process.env.VERSION))
.pipe(gulp.dest('build/static'));
console.log("pack-priceChart task done @", new Date())
});
gulp.task('pack-contentjs', function () {
return gulp.src([
'node_modules/weui.js/dist/weui.min.js',
'static/content_script.js'
])
.pipe(concat('content_script.js'))
.pipe(gulp.dest('build/static'));
});
gulp.task('pack-content_style', function () {
return gulp.src(['static/style/weui.min.css', 'static/style/style.css'])
.pipe(concat('contentstyle.css'))
.pipe(cleanCss())
.pipe(gulp.dest('build/static/style'));
});
gulp.task('pack-popup_style', function () {
return gulp.src([
'static/style/weui.min.css',
'node_modules/tippy.js/dist/tippy.css',
'static/style/popup.css'
])
.pipe(concat('popupstyle.css'))
.pipe(cleanCss())
.pipe(gulp.dest('build/static/style'));
});
gulp.task('move-static', ['build-bundle'], function () {
gulp.src([
'static/audio/*.*', 'static/image/*.*', 'static/image/*/*.*', 'static/style/*.css'
], { base: './' })
.pipe(gulp.dest('build'));
});
gulp.task('move-js', [], function () {
gulp.src([
'static/start.js',
'static/mobile_script.js',
'node_modules/zepto/dist/zepto.min.js',
'node_modules/dialog-polyfill/dialog-polyfill.js',
'node_modules/@sunoj/touchemulator/touch-emulator.js',
])
.pipe(gulp.dest('build/static'));
});
gulp.task('move-file', [], async function () {
let browser = (process.env.BROWSER ? process.env.BROWSER : 'chrome')
await new Promise((resolve, reject) => {
gulp.src([
'manifest.json', '*.html'
])
.pipe(replace('{{version}}', process.env.VERSION))
.pipe(replace('{{buildid}}', process.env.BUILDID))
.pipe(replace('{{browser}}', browser))
.pipe(preprocess({
context: {
Browser: browser
}
}))
.pipe(gulp.dest('build'))
.on("end", resolve);
});
console.log('move-file done')
});
gulp.task('build-bundle', ['move-file'], async function () {
console.log('build-bundle start')
await bundleBuild('static/background.js')
await bundleBuild('static/popup.js')
console.log('build-bundle done')
});
gulp.task('move-build-bundle', ['build-bundle'], async function () {
console.log('move-build-bundle start')
let browser = (process.env.BROWSER ? process.env.BROWSER : 'chrome')
await new Promise((resolve, reject) => {
gulp.src([
'dist/*.js'
])
.pipe(replace('{{version}}', process.env.VERSION))
.pipe(replace('{{buildid}}', process.env.BUILDID))
.pipe(replace('{{browser}}', browser))
.pipe(preprocess({
context: {
Browser: browser
}
}))
.pipe(gulp.dest('build/static'))
.on("end", resolve);
});
console.log('move-build-bundle done')
});
gulp.task('default', [
'move-file', 'move-js', 'pack-priceChart', 'pack-content_style', 'pack-popup_style',
'pack-contentjs', 'build-bundle', 'move-build-bundle', 'move-static'
]);
gulp.task('dev', ['default', 'watch']);