forked from opensourcehk/kaidemo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
109 lines (93 loc) · 2.85 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
'use strict';
const gulp = require('gulp-help')(require('gulp'));
const gutil = require("gulp-util");
const util = require('gulp-util');
const rename = require('gulp-rename');
const imagemin = require('gulp-imagemin');
const sass = require('gulp-sass');
const cleanCss = require('gulp-clean-css');
const htmlmin = require('gulp-htmlmin');
const webpack = require('webpack');
const merge = require('webpack-merge');
const config = require('./webpack.config');
const fs = require('fs');
const WebpackDevServer = require('webpack-dev-server');
const {NODE_ENV} = process.env;
gulp.task('image', 'Build imagemin version of ./assets/images/**/* into ./public/images', () => {
return gulp.src('./assets/images/**/*.*')
.pipe(imagemin())
.on('error', util.log)
.pipe(gulp.dest('public/images'));
});
gulp.task('css', 'Build ./assets/scss/*.scss into ./public', () => {
return gulp.src(['./assets/scss/*.scss', './assets/scss/*.css'])
.pipe(sass())
.on('error', util.log)
.pipe(gulp.dest('public'))
.pipe(rename({
suffix: '.min'
}))
.pipe(cleanCss())
.pipe(gulp.dest('public'));
});
gulp.task('server', 'Start a webpack-dev-server for the project at http://localhost:8080', () => {
const devConfig = merge(config, {
entry: {
app: [
'webpack-dev-server/client?http://localhost:8080/',
'./assets/js/index.jsx'
]
}
});
const compiler = webpack(devConfig);
compiler.plugin('done', (stats) => {
util.log('[webpack]', stats.toString({
version: true,
timings: true,
assets: true,
chunks: true,
chunkModules: true,
modules: true
}));
fs.writeFile('./webpack.json', JSON.stringify(stats.toJson('verbose')));
});
const server = new WebpackDevServer(compiler, {
hot: true,
contentBase: './public'
});
server.listen(8080);
});
gulp.task('js', 'Build javascripts bundle into ./public/js/app.js', (cb) => {
webpack(config, (e, stats) => {
if (e) {
throw new gutil.PluginError('[webpack]', e);
} else {
util.log('[webpack]', stats.toString({
version: true,
timings: true,
assets: true,
chunks: true,
chunkModules: true,
modules: true
}));
fs.writeFile('./webpack.json', JSON.stringify(stats.toJson('verbose')));
}
cb();
});
});
gulp.task('watch:css', false, () => {
return gulp.watch([
'./assets/scss/**/*.scss',
'./assets/scss/**/*.css'
], ['css']);
});
gulp.task('watch:image', false, () => {
return gulp.watch([
'./assets/images/**/*.*'
], ['image']);
});
gulp.task('watch', 'Monitor and rebuild images and css files.',
['watch:image', 'watch:css']);
gulp.task('build:dev', false, ['js', 'image', 'css', 'server']);
gulp.task('dev', 'Development mode. Starts',['build:dev', 'watch']);
gulp.task('build', 'Build the site.', ['image', 'css', 'js']);