-
Notifications
You must be signed in to change notification settings - Fork 41
/
gulpfile.coffee
123 lines (107 loc) · 3.45 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
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'
_ = require 'underscore'
# Load plugins
$ = require('gulp-load-plugins')()
# CSS
gulp.task('css', ->
gulp.src(['src/styles/*.sass', 'src/styles/*.scss'])
.pipe($.compass({
css: 'public/'
sass: 'src/styles'
image: 'src/styles/images'
style: 'nested'
comments: false
bundle_exec: true
time: true
require: [
'susy',
'modular-scale',
'normalize-scss',
'sass-css-importer',
'sassy-buttons',
'breakpoint']
}))
.on('error', (err) ->
gutil.log err
)
.pipe($.size())
.pipe(gulp.dest('public/'))
.pipe(map((a, cb) ->
if devServer.invalidate? then devServer.invalidate()
cb()
))
)
gulp.task('copy-assets', ->
gulp.src('assets/**')
.pipe(gulp.dest('public'))
.pipe($.size())
)
# Some quick notes on using fontcustom.
# First you need to install some additional software
# as detailed at https://github.com/FontCustom/fontcustom#installation
# On MacOSX, this comment was the only way I got things to work: https://github.com/FontCustom/fontcustom/issues/209#issuecomment-48014939
# Otherwise I got a Python import error.
#
# Then once things are working, things here are setup so that the generated font
# is base64 encoded and included in the css file. For this to work, you
# need to edit the generated scss file at src/styles/_fontcustom.scss to remove
# its font-face imports.
# Font compilation
gulp.task('font', $.shell.task([
'fontcustom compile'
]))
gulp.task('font-base-64', ->
gulp.src('assets/fonts/*.ttf')
.pipe($.rename('fontcustom.ttf'))
.pipe($.cssfont64())
.pipe($.rename('_fontcustom_embedded.scss'))
.pipe(gulp.dest('src/styles/'))
)
gulp.task "webpack:build", ['css'], (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", ['css'], (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", ['css'], (callback) ->
# Ensure there's a `./public/main.css` file that can be required.
touch.sync('./public/main.css', time: new Date(0))
# 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
gulp.task 'default', ->
gulp.start 'build'
gulp.task 'build', ['webpack:build', 'copy-assets']
gulp.task 'watch', ['css', 'copy-assets', 'webpack-dev-server'], ->
gulp.watch(['src/styles/**'], ['css'])
gulp.watch(['assets/**'], ['copy-assets'])