-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
114 lines (96 loc) · 2.95 KB
/
gulpfile.js
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
process.env.DEBUG = process.env.DEBUG || 'ar:*';
require('babel-register');
const gulp = require('gulp');
// const gutil = require('gulp-util');
const notify = require('gulp-notify');
const rename = require('gulp-rename');
const plumber = require('gulp-plumber');
const sourcemaps = require('gulp-sourcemaps');
const stylus = require('gulp-stylus');
const swiss = require('kouto-swiss');
// const debugFactory = require('debug');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const history = require('connect-history-api-fallback');
const browserSync = require('browser-sync');
const render = require('gulp-render-react');
const yargs = require('yargs');
const webpackConfig = require('./webpack.config');
// const debug = debugFactory('immortan:gulp');
const sync = browserSync.create('ar-sync-server');
const reload = sync.reload.bind(sync);
// user definable ports
const port = yargs.argv.port || process.env.PORT || 3000;
// make sure sync ui port does not interfere with proxy port
const UIPort = yargs.argv['ui-port'] || process.env.UI_PORT || 3002;
const paths = {
template: './template.jsx',
stylus: './client/index.styl',
stylusFiles: [
'./client/**/*.styl'
],
public: './public'
};
function errorHandler() {
const args = Array.prototype.slice.call(arguments);
// Send error to notification center with gulp-notify
notify.onError({
title: 'Compile Error',
message: '<%= error %>'
}).apply(this, args);
// Keep gulp from hanging on this task
this.emit('end');
}
gulp.task('stylus', function() {
return gulp.src(paths.stylus)
.pipe(plumber({ errorHandler: errorHandler }))
.pipe(sourcemaps.init())
.pipe(stylus({
use: swiss()
}))
.pipe(sourcemaps.write())
.pipe(rename('main.css'))
.pipe(gulp.dest(paths.public))
.pipe(reload({ stream: true }));
});
const syncDependents = [
'create-html'
];
gulp.task('create-html', function() {
return gulp.src(paths.template)
.pipe(render({
type: 'markup'
}))
.pipe(rename('index.html'))
.pipe(gulp.dest(paths.public))
.pipe(reload({ stream: true }));
});
gulp.task('serve', syncDependents, function() {
webpackConfig.entry.bundle = [
'webpack/hot/dev-server',
'webpack-hot-middleware/client'
].concat(webpackConfig.entry.bundle);
const bundler = webpack(webpackConfig);
sync.init(null, {
port,
server: paths.public,
open: false,
logLeval: 'debug',
files: paths.syncWatch,
ui: { port: UIPort },
middleware: [
webpackDevMiddleware(bundler, {
publicPath: webpackConfig.output.publicPath,
stats: 'errors-only'
}),
webpackHotMiddleware(bundler),
history()
]
});
});
gulp.task('watch', function() {
// gulp.watch(paths.stylusFiles, ['stylus']);
gulp.watch(paths.template, ['create-html']);
});
gulp.task('default', [ 'create-html', 'serve', 'watch' ]);