-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
66 lines (60 loc) · 1.72 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
// npm i gulp-serve gulp-livereload gulp-util gulp connect-livereload webpack
// npm i style-loader html-loader css-loader
var serve = require('gulp-serve')
var livereload = require('gulp-livereload')
var webpack = require('webpack')
var gutil = require('gulp-util')
var gulp = require('gulp')
var inject = require('connect-livereload')()
var path = require('path')
var myConfig = {
entry: './example/index.js',
output: {
path: 'example',
filename: 'bundle.js'
},
module: {
loaders: [
{test: /\.css$/, loader: 'style!css'},
{test: /\.html$/, loader: 'html'}
]
}
}
// for debugging
myConfig.devtool = 'sourcemap'
myConfig.debug = true
var paths = {
scripts: ['index.js', 'ptr.css', 'example/index.js'],
// file list for watching
asserts: ['example/index.js', 'exmaple/*.css', 'example/index.html']
}
gulp.task('default', ['build-dev'])
gulp.task('build-dev', ['webpack:build-dev', 'serve'], function () {
livereload.listen({
start: true
})
// build js files on change
gulp.watch(paths.scripts, ['webpack:build-dev'])
var watcher = gulp.watch(paths.asserts)
watcher.on('change', function (e) {
livereload.changed(e.path)
})
})
// static server
gulp.task('serve', serve({
root: [__dirname],
// inject livereload script ot html
middleware: inject
}))
var devCompiler = webpack(myConfig)
var outputFile = path.resolve(myConfig.output.path, myConfig.output.filename)
gulp.task('webpack:build-dev', function (callback) {
devCompiler.run(function (err, stats) {
if (err) throw new gutil.pluginError('webpack:build-dev', err) //eslint-disable-line
gutil.log('[webpack:build-dev]', stats.toString({
colors: true
}))
livereload.changed(outputFile)
callback()
})
})