-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.coffee
71 lines (62 loc) · 2.11 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
gulp = require 'gulp'
gutil = require 'gulp-util'
webpack = require("webpack")
WebpackDevServer = require("webpack-dev-server")
webpackConfig = require("./webpack.config.js")
webpackProductionConfig = require("./webpack.production.config.js")
map = require 'map-stream'
touch = require 'touch'
# Load plugins
$ = require('gulp-load-plugins')()
gulp.task "webpack:build", (callback) ->
# Run webpack.
webpack webpackProductionConfig, (err, stats) ->
throw new gutil.PluginError("webpack:build", err) if err
gutil.log "[webpack:build]", stats.toString(colors: true)
callback()
return
# Create a single instance of the compiler to allow caching.
devCompiler = webpack(webpackConfig)
gulp.task "webpack:build-dev", (callback) ->
# Run webpack.
devCompiler.run (err, stats) ->
throw new gutil.PluginError("webpack:build-dev", err) if err
gutil.log "[webpack:build-dev]", stats.toString(colors: true)
callback()
return
return
devServer = {}
gulp.task "webpack-dev-server", (callback) ->
# Start a webpack-dev-server.
devServer = new WebpackDevServer(webpack(webpackConfig),
contentBase: './public/'
hot: true
watchOptions:
aggregateTimeout: 100
poll: 300
noInfo: true
)
devServer.listen 8080, "0.0.0.0", (err) ->
throw new gutil.PluginError("webpack-dev-server", err) if err
gutil.log "[webpack-dev-server]", "http://localhost:8080"
callback()
return
csp = (req, res, next) ->
res.setHeader 'Content-Security-Policy', "frame-ancestors 'none'"
next()
prodRedirect = (req, res, next) ->
if req.headers.host.indexOf('app.xrespond.com') == -1
res.writeHead 302, Location: 'http://app.xrespond.com'
res.end()
else
next()
gulp.task 'prod-server', ['webpack:build'], ->
$.connect.server
root: ['./public'],
port: process.env.PORT || 5000,
livereload: false
middleware: (connect, opt) ->
if process.env.NODE_ENV != 'production' then [connect.basicAuth('kisnip','jotrog'),csp] else [csp,prodRedirect]
gulp.task 'default', -> gulp.start 'build'
gulp.task 'build', ['webpack:build']
gulp.task 'watch', ['webpack-dev-server']