-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.coffee
101 lines (88 loc) · 2.79 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
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
# See example gulpfile.js for file system development build:
# https://github.com/webpack/webpack-with-common-libs/blob/master/gulpfile.js
del = require 'del'
gulp = require 'gulp'
$ = require('gulp-load-plugins')();
webpack = require 'webpack'
WebpackDevServer = require 'webpack-dev-server'
webpackConfig = require './webpack.config.coffee'
vinylPaths = require 'vinyl-paths'
# Default task
gulp.task 'default', ['webpack-dev-server'], ->
############################################################
# Development build
############################################################
gulp.task 'webpack-dev-server', (callback) ->
# modify some webpack config options
conf = Object.create webpackConfig
conf.devtool = 'source-map'
conf.debug = true
# Start a webpack-dev-server
new WebpackDevServer webpack(conf),
contentBase: conf.contentBase
stats:
colors: true
.listen 8000, 'localhost', (err) ->
throw new $.util.PluginError('webpack-dev-server', err) if err
$.util.log '[webpack-dev-server]', 'http://localhost:8000/webpack-dev-server/index.html'
############################################################
# Production build
############################################################
gulp.task 'clean', del.bind null, ['dist']
gulp.task 'build', ['webpack:build'], ->
revAll = new $.revAll
dontRenameFile: [
/^\/favicon.ico$/g
/^\/CNAME$/g
/^\/index.html$/g
/^\/app.html$/g
/^\/callback.html$/g
/^\/robots.txt$/g
]
gulp.src 'src/**'
.pipe $.if 'src/images/*'
, $.changed 'dist/images'
, $.cache $.imagemin
progressive: true
interlaced: true
.pipe $.if '*.css'
, $.csso()
# , $.autoprefixer
# browsers: [
# 'ie >= 10'
# 'ie_mob >= 10'
# 'ff >= 30'
# 'chrome >= 34'
# 'safari >= 7'
# 'opera >= 23'
# 'ios >= 7'
# 'android >= 4.4'
# 'bb >= 10'
# ]
.pipe $.if '*.html', $.minifyHtml
empty: true
spare: true
comments: true
.pipe $.if '*.js', $.uglify()
# .pipe revAll.revision()
# .pipe gulp.dest 'dist'
# .pipe revAll.manifestFile()
# .pipe gulp.dest 'dist'
# .pipe revAll.versionFile()
.pipe gulp.dest 'dist'
gulp.task 'webpack:build', (callback) ->
conf = Object.create webpackConfig
conf.plugins = conf.plugins.concat new webpack.DefinePlugin
'process.env':
NODE_ENV: JSON.stringify('production')
, new webpack.optimize.DedupePlugin()
, new webpack.optimize.UglifyJsPlugin()
# run webpack
webpack conf, (err, stats) ->
throw new $.util.PluginError('webpack:build', err) if err
$.util.log '[webpack:build]', stats.toString colors: true
callback()
gulp.task 'deploy', ['build'], ->
gulp.src 'dist'
.pipe $.subtree()
.pipe vinylPaths(del)