forked from chemzqm/scroll-select
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
86 lines (78 loc) · 2.31 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
var growl = require('growl')
var serve = require('gulp-live-serve')
var livereload = require('gulp-livereload')
var webpack = require('webpack')
var WebpackDevServer = require('webpack-dev-server')
var gutil = require('gulp-util')
var gulp = require('gulp')
var path = require('path')
var config = require('./webpack.config')
// test entry file
var testIndex = './test/test.js'
// webpack-dev-sserve port
var port = 8080
// no conflict
var myConfig = Object.assign({}, config, {
devtool: 'sourcemap',
debug: true
})
var paths = {
// file list for webpack build
scripts: ['style.css', 'index.js', 'example/index.js'],
// file list for reload
asserts: ['example/bundle.js', 'example/*.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)
growl(path.basename(e.path))
})
})
// static server
gulp.task('serve', serve({
root: __dirname,
middlewares: []
}))
gulp.task('webpack:build-dev', function (callback) {
var devCompiler = webpack(myConfig)
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
}))
callback()
})
})
gulp.task('webpack:test', function (callback) {
var entry = [
'stack-source-map/register.js',
'webpack-dev-server/client?http://localhost:' + port,
'webpack/hot/dev-server',
'mocha!' + testIndex
]
var config = Object.create(myConfig)
config.entry = entry
config.plugins = config.plugins || []
// webpack need this to send request to webpack-dev-server
config.plugins.push(new webpack.HotModuleReplacementPlugin())
// Get line of error in mocha
config.devtool = 'cheap-module-eval-source-map'
// must have
config.output.path = __dirname
var compiler = webpack(config)
config.module = myConfig.module
var server = new WebpackDevServer(compiler, {
publicPath: '/',
inline: true,
historyApiFallback: false,
stats: { colors: true }
})
server.listen(port, 'localhost', callback)
})