forked from udacity/mws-restaurant-stage-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
71 lines (57 loc) · 1.89 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
/* eslint-disable */
const gulp = require('gulp');
const nunjucks = require('gulp-nunjucks');
const concat = require('gulp-concat');
const gutil = require("gulp-util");
const watch = require('gulp-watch');
const open = require('opn');
const webpack = require("webpack");
const webpackStream = require('webpack-stream');
const WebpackDevServer = require("webpack-dev-server");
/* CONFIG FILES */
const BUILD_DEV_CONFIG = require('./webpack.build.dev.js');
const BUILD_PROD_CONFIG = require('./webpack.build.prod.js');
const SERVE_DEV_CONFIG = require('./webpack.serve.dev.js');
const paths = {
src: './src/',
build: './dist/'
};
gulp.task('nunjucks:precompile', () =>
gulp.src('src/app/**/*.+(njk)')
.pipe(nunjucks.precompile({
name: file => {
var path = file.relative;
if(path.lastIndexOf('\\') > 0)
return (`${path.substr(path.lastIndexOf('\\') + 1)}`);
else
return (`${path.substr(path.lastIndexOf('/') + 1)}`);
}
}))
.pipe(concat('templates.js'))
.pipe(gulp.dest('src/lib'))
);
gulp.task('webpack:serve:dev', ['nunjucks:precompile'], () => {
var myConfig = Object.create(SERVE_DEV_CONFIG);
new WebpackDevServer(webpack(myConfig), {
port: 9000,
disableHostCheck: true,
host: 'localhost',
historyApiFallback: true,
open: true,
hot: true,
stats: {
colors: true
},
}).listen(9000, "localhost", function(err) {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
open(process.env.BASEURL);
});
});
gulp.task('webpack:build:prod', ['nunjucks:precompile'] ,() => {
return webpackStream(BUILD_PROD_CONFIG)
.pipe(gulp.dest(`${paths.build}`));
});
gulp.task('webpack:build:dev', ['nunjucks:precompile'] ,() => {
return webpackStream(BUILD_DEV_CONFIG)
.pipe(gulp.dest(`${paths.build}`));
});