forked from khaled/react-express-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.coffee
96 lines (82 loc) · 2.61 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
gulp = require 'gulp'
gutil = require 'gulp-util'
livereload = require 'gulp-livereload'
nodemon = require 'gulp-nodemon'
plumber = require 'gulp-plumber'
gwebpack = require 'gulp-webpack'
less = require 'gulp-less'
postcss = require 'gulp-postcss'
autoprefixer = require 'autoprefixer-core'
rimraf = require 'rimraf'
GLOBAL.Promise = (require 'es6-promise').Promise # to make gulp-postcss happy
src_path = "src"
components_path = "bower_components"
modules_path = "node_modules"
semantic_path = "#{modules_path}/semantic-ui-css"
dist_path = "dist"
err = (x...) -> gutil.log(x...); gutil.beep(x...)
webpack = (name, ext, watch) ->
options =
# bail: true
watch: watch
cache: true
devtool: "source-map"
output:
filename: "#{name}.js"
sourceMapFilename: "[file].map"
resolve:
extensions: ["", ".webpack.js", ".web.js", ".js", ".jsx", ".coffee", ".cjsx"]
modulesDirectories: [components_path, modules_path]
module:
loaders: [
{
test: /\.coffee$/
loader: "coffee-loader"
}
{
test: [/\.js$/, /\.jsx$/]
exclude: [new RegExp(modules_path), new RegExp(components_path)]
loader: "babel-loader"
}
{
test: /\.cjsx$/
loader: "transform?coffee-reactify"
}
]
gulp.src("#{src_path}/#{name}.#{ext}")
.pipe(gwebpack(options))
.pipe(gulp.dest(dist_path))
js = (watch) -> webpack("client", "cjsx", watch)
gulp.task 'js', -> js(false)
gulp.task 'js-dev', -> js(true)
gulp.task 'css', ->
gulp.src("#{src_path}/styles.less")
.pipe(plumber())
.pipe(less(
paths: [components_path, modules_path]
))
.on('error', err)
.pipe(postcss([autoprefixer(browsers: ["last 2 versions", "ie 8", "ie 9"])]))
.pipe(gulp.dest(dist_path))
gulp.task 'clean', ->
rimraf.sync(dist_path)
gulp.task 'copy', ->
gulp.src("#{src_path}/*.html").pipe(gulp.dest(dist_path))
gulp.src("#{src_path}/favicon.ico").pipe(gulp.dest(dist_path))
gulp.src("#{semantic_path}/themes/default/assets/**/*").pipe(gulp.dest("#{dist_path}/themes/default/assets/"))
gulp.task 'build', ['clean', 'copy', 'css', 'js']
server_main = "#{src_path}/server.coffee"
gulp.task 'server', ->
nodemon
script: server_main
watch: [server_main]
execMap:
coffee: "coffee"
env:
PORT: process.env.PORT or 3000
gulp.task 'default', ['clean', 'copy', 'css', 'server', 'js-dev', 'watch']
gulp.task 'watch', ['copy'], ->
livereload.listen()
gulp.watch(["#{dist_path}/**/*"]).on('change', livereload.changed)
gulp.watch ["#{src_path}/**/*.less"], ['css']
gulp.watch ["#{src_path}/**/*.html"], ['copy']