-
Notifications
You must be signed in to change notification settings - Fork 586
/
gulpfile.coffee
139 lines (110 loc) · 3.55 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
_ = require "underscore"
$ = require("gulp-load-plugins")()
gulp = require "gulp"
path = require "path"
rename = require "gulp-rename"
merge = require "merge-stream"
deepExtend = require "deep-extend"
runSequence = require "run-sequence"
autoprefixer = require "autoprefixer-core"
webpack = require "webpack"
WebpackDevServer = require "webpack-dev-server"
####################
## CONFIG
####################
config =
paths:
app: "app"
tmp: ".tmp"
dist: "dist"
scripts: "app/scripts"
styles: "app/styles"
assets: "app/assets"
serverPort: 9000
webpack: ->
resolveLoader:
moduleDirectories: ["node_modules"]
output:
path: path.join __dirname, config.paths.tmp
filename: "bundle.js"
resolve:
extensions: ["", ".js", ".coffee", ".scss", ".css", ".ttf"]
alias:
"assets": path.join __dirname, config.paths.assets
module:
loaders: [
{ test: /\.scss$/, loaders: ["style", "css", "postcss-loader", "sass"] }
{ test: /\.coffee$/, loaders: ["coffee"] }
{ test: /\.png/, loaders: ["url-loader?mimetype=image/png"] }
{ test: /\.ttf/, loaders: ["url-loader?mimetype=font/ttf"] }
]
postcss: [autoprefixer({ browsers: ["last 2 version"] })]
webpackEnvs: ->
development:
devtool: "eval"
debug: true
entry: [
"webpack-dev-server/client?http://0.0.0.0:#{config.serverPort}"
"webpack/hot/only-dev-server"
"./#{config.paths.scripts}/app"
]
plugins: [
new webpack.HotModuleReplacementPlugin
new webpack.NoErrorsPlugin()
]
distribute:
entry: [
"./#{config.paths.scripts}/app"
]
plugins: [
new webpack.optimize.DedupePlugin()
new webpack.optimize.UglifyJsPlugin(
compressor: { warnings: false }
)
]
config = _(config).mapObject (val) ->
if _.isFunction(val) then val() else val
webpackers = _(config.webpackEnvs).mapObject (val) ->
webpack deepExtend({}, config.webpack, val)
####################
## TASKS
####################
gulp
.task "copy-assets", ->
assets = gulp
.src path.join(config.paths.assets, "**")
.pipe gulp.dest("#{config.paths.tmp}/assets")
instructions = gulp
.src path.join(config.paths.app, "index.html")
.pipe gulp.dest(config.paths.tmp)
merge assets, instructions
.task "copy-page-files", ->
gulp
.src path.join(config.paths.assets, "{instructions.html,page.png,result.html,beach.jpg}")
.pipe gulp.dest(path.join config.paths.dist, "assets")
.task "webpack-dev-server", (done) ->
server = new WebpackDevServer webpackers.development,
contentBase: config.paths.tmp
hot: true
watchDelay: 100
noInfo: true
server.listen config.serverPort, "0.0.0.0", (err) ->
throw new $.util.PluginError("webpack-dev-server", err) if err
$.util.log $.util.colors.green(
"[webpack-dev-server] Server running on http://localhost:#{config.serverPort}")
done()
.task "build", (done) ->
webpackers.distribute.run (err, stats) ->
throw new $.util.PluginError("webpack:build", err) if err
done()
.task "serve", ["copy-assets", "webpack-dev-server"], ->
gulp.watch ["app/assets/**"], ["copy-assets"]
.task "inline", ->
gulp
.src "#{config.paths.tmp}/index.html"
.pipe $.inlineSource()
.pipe rename(basename: "editor")
.pipe gulp.dest("#{config.paths.dist}")
.task "dist", ->
runSequence "copy-assets", "build", "inline", "copy-page-files"
.task "default", ["serve"]