-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
103 lines (77 loc) · 1.99 KB
/
gulpfile.babel.js
File metadata and controls
103 lines (77 loc) · 1.99 KB
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
'use strict';
import gulp from 'gulp';
import webpack from 'webpack';
import path from 'path';
import fs from 'fs';
import gutil from 'gulp-util';
import del from 'del';
import serve from 'browser-sync';
import webpackDevMiddleware from 'webpack-dev-middleware';
import historyApiFallback from 'connect-history-api-fallback';
let root = 'src';
let resolveToApp = (glob = '') => {
return path.join(root, 'app', glob);
};
let resolveToComponents = (glob = '') => {
return path.join(root, 'app/components', glob);
};
let paths = {
js: resolveToComponents('**/*!(.spec.js).js'),
scss: resolveToApp('**/*.scss'),
html: [
resolveToApp('**/*.html'),
path.join(root, 'index.html')
],
entry: [
'babel-polyfill',
path.join(__dirname, root, 'app/app.js')
],
output: root,
dest: path.join(__dirname, 'dist')
};
gulp.task('webpack', ['clean'], (cb) => {
const config = require('./webpack.dist.config');
config.entry.app = paths.entry;
webpack(config, (err, stats) => {
if(err) {
throw new gutil.PluginError("webpack", err);
}
gutil.log("[webpack]", stats.toString({
colors: true,
chunks: false,
errorDetails: true
}));
cb();
});
});
gulp.task('serve', () => {
const config = require('./webpack.dev.config');
config.entry.app = [
//TODO add HMR
].concat(paths.entry);
var compiler = webpack(config);
var devServer = serve({
port: process.env.PORT || 3000,
open: false,
server: {baseDir: root},
middleware: [
historyApiFallback(),
webpackDevMiddleware(compiler, {
stats: {
colors: true,
chunks: false,
modules: false
},
publicPath: config.output.publicPath
})
]
});
gulp.watch('dist/app.bundle.js').on('change', devServer.reload);
});
gulp.task('clean', (cb) => {
del([paths.dest]).then(function (paths) {
gutil.log("[clean]", paths);
cb();
})
});
gulp.task('default', ['serve']);