-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.coffee
58 lines (52 loc) · 1.47 KB
/
gulpfile.coffee
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
'use strict'
fs = require('fs')
gulp = require('gulp')
gutil = require('gulp-util')
sequence = require('run-sequence')
settings = require('./tasks/settings')
env = 'dev'
gulp.task 'html', (cb) ->
`var fs`
html = require('./tasks/template')
fs = require('fs')
fs.writeFile 'build/index.html', html(env), cb
gulp.task 'del', (cb) ->
del = require('del')
del [ 'build/**/*' ], cb
gulp.task 'webpack-build', (cb) ->
webpack = require('webpack')
webpackBuild = require('./tasks/webpack-build')
config = settings.get(env)
info =
__dirname: __dirname
isMinified: config.isMinified
useCDN: config.useCDN
cdn: config.cdn
env: config.env
webpack webpackBuild(info), (err, stats) ->
if err
throw new (gutil.PluginError)('webpack', err)
gutil.log '[webpack]', stats.toString()
jsonData = stats.toJson()
fileContent = JSON.stringify(jsonData.assetsByChunkName)
fs.writeFileSync 'tasks/assets.json', fileContent
cb()
gulp.task 'webpack-server', (cb) ->
webpack = require('webpack')
serverConfig = require('./tasks/webpack-server')
webpack(serverConfig).run (err, stats) ->
if err
console.log err
else
console.log stats.toString()
cb()
webpack(serverConfig).watch 100, (err, stats) ->
if err
console.log err
else
console.log stats.toString()
gulp.task 'dev', (cb) ->
sequence 'html', 'webpack-dev', cb
gulp.task 'build', (cb) ->
env = 'build'
sequence 'del', 'webpack-build', 'html', cb