-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
136 lines (108 loc) · 3.31 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
* Gulp Config
*/
// Packages
const PATH = require("path");
const GULP = require("gulp");
const WATCH = require("gulp-watch");
const SOURCEMAPS = require("gulp-sourcemaps");
const SASS = require("gulp-sass");
const POSTCSS = require("gulp-postcss");
const AUTOPREFIXER = require("autoprefixer");
const RENAME = require("gulp-rename");
const GUTIL = require("gulp-util");
const WEBPACK = require("webpack-stream");
const UGLIFY = require("gulp-uglify");
// Paths
const SRC = PATH.join(__dirname, "src");
const DIST = PATH.join(__dirname, "dist");
// css
const CSS_SRC = PATH.join(SRC, "scss");
const CSS_DIST = PATH.join(DIST, "css");
// js
const JS_SRC = PATH.join(SRC, "js");
const JS_DIST = PATH.join(DIST, "js");
// Patterns
const JS_ENTRY = PATH.join(JS_SRC, "app.js");
const JS_FILES = PATH.join(JS_SRC, "**", "*.js");
const SCSS_WATCH_ENTRY = [ PATH.join(CSS_SRC, "**", "*.scss") ];
const SCSS_BUILD_ENTRY = [ PATH.join(CSS_SRC, "**", "*.scss"), "!" + PATH.join(CSS_SRC, "**", "_*.scss") ];
/**
* Tasks
*/
GULP.task("js:build:development", () => {
/**
* require webpack below fixes the issue where gulp-webpack
* uses webpack v1 and we want to use webpack v2.
*/
const config = Object.assign({}, require("./webpack.config.js"));
config.output.filename = "bundle.js";
return GULP.src(JS_ENTRY)
.pipe(WEBPACK(config, require("webpack")))
.pipe(GULP.dest(JS_DIST));
});
GULP.task("js:watch", [ "js:build:development" ], () => {
WATCH([ JS_FILES ], () => {
GULP.start("js:build:development");
});
});
GULP.task("js:build:production", () => {
/**
* require webpack below fixes the issue where gulp-webpack uses webpack v1 and we want to use webpack v2.
*/
const _webpack = require("webpack");
let config = Object.assign({}, require("./webpack.config.js"), {
plugins: [
new _webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true
},
output: {
comments: false
}
})
]
});
config.output.filename = "bundle.min.js";
return GULP.src(JS_ENTRY)
.pipe(WEBPACK(config, _webpack))
.pipe(GULP.dest(JS_DIST));
});
// Parse SASS
GULP.task("scss:build:development", () => {
return GULP.src(SCSS_BUILD_ENTRY)
.pipe(SOURCEMAPS.init())
.pipe(SASS().on("error", GUTIL.log))
.pipe(POSTCSS([ AUTOPREFIXER({ browsers: [ "> 5%", "IE 9" ] }) ]))
.pipe(SOURCEMAPS.write())
.pipe(GULP.dest(CSS_DIST));
});
// Watch SASS changes
GULP.task("scss:watch", [ "scss:build:development" ], () => {
WATCH(SCSS_WATCH_ENTRY, () => {
GULP.start("scss:build:development");
});
});
// Minify SASS/CSS
GULP.task("scss:build:production", () => {
return GULP.src(SCSS_BUILD_ENTRY)
.pipe(SASS({ outputStyle: "compressed" }).on("error", GUTIL.log))
.pipe(POSTCSS([ AUTOPREFIXER({ browsers: [ "> 5%", "IE 9" ] }) ]))
.pipe(RENAME({ suffix: ".min" }))
.pipe(GULP.dest(CSS_DIST));
});
GULP.task("js:build:bootstraper", () => {
return GULP.src(PATH.join(JS_SRC, "bootstraper.js"))
.pipe(UGLIFY())
.pipe(RENAME({ suffix: ".min" }))
.pipe(GULP.dest(JS_DIST));
});
/**
* Task Aliases
*/
GULP.task("default", () => {
GULP.start("scss:watch");
GULP.start("js:watch");
});
GULP.task("build", [ "scss:build:production", "js:build:production", "js:build:bootstraper" ]);