-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
69 lines (63 loc) · 1.62 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
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const chalk = require('chalk');
const gulp = require('gulp');
const path = require('path');
const rimraf = require('rimraf');
const tslint = require('gulp-tslint');
const getConfig = require('./webpack.config.js');
const port = process.env.PORT;
function clearConsole() {
process.stdout.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H');
}
function start(compiler, call) {
const devServer = new WebpackDevServer(compiler, {
contentBase: path.resolve(__dirname, 'static'),
hotOnly: true,
hot: true,
historyApiFallback: {
rewrites: [
{ from: /\/.*/, to: '/' }
]
}
}).listen(port || 8000, '127.0.0.1', () => {
process.stdout.write(chalk.bgGreen(`Webpack Server running on port: ${chalk.red(port || 8000)}`));
});
['SIGINT', 'SIGTERM'].forEach((sig) => {
process.on(sig, () => {
call();
devServer.close();
process.exit();
});
});
return devServer;
}
gulp.task('dev', (call) => {
const compiler = webpack(getConfig(port));
clearConsole();
start(compiler, call);
});
gulp.task('build', (call) => {
rimraf.sync('dist', ['rmdir']);
webpack(getConfig(), (err) => {
if (err) {
process.stdout.write(chalk.bgCyan('webpack 编译出错'));
}
call();
process.exit();
});
});
gulp.task('lint', async () => {
await gulp
.src(['src/**/*.tsx', 'src/**/*.ts'])
.pipe(
tslint({
formatter: 'verbose',
})
)
.pipe(
tslint.report({
summarizeFailureOutput: true,
})
);
});