-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.babel.js
101 lines (91 loc) · 2.54 KB
/
gulpfile.babel.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
"use strict";
import gulp from "gulp";
import webserver from "gulp-webserver";
import path from "path";
import pug from "gulp-pug";
import inline_source from "gulp-inline-source";
import rename from "gulp-rename";
import webpack from "webpack";
import sass from "gulp-sass";
gulp.task("start", () => {
const dist = path.resolve("dist");
gulp.src(dist)
.pipe(webserver({
livereload: true,
directoryListing: false,
open: true,
}));
});
gulp.task("build", ["build-js", "build-css"], () => {
gulp.start("build-html");
});
gulp.task("build-html", () => {
const src = path.resolve("src");
const dist = path.resolve("dist");
// ミニファイして出力
gulp.src(path.join(src, "*.pug"))
.pipe(pug({pretty: false}))
.pipe(gulp.dest(dist))
// CSS/JSを埋め込む
.pipe(inline_source())
.pipe(rename({suffix: ".bundle"}))
.pipe(gulp.dest(dist));
});
gulp.task("build-js", (callback) => {
const src = path.resolve("src", "js");
const dist = path.resolve("dist", "js");
const config = {
entry: {
"script": "script.es",
},
resolve: {
modules: [
src,
"node_modules",
],
},
output: {
path: dist,
filename: "[name].min.js",
},
module: {
loaders: [
{
test: /\.es/,
loader: "babel-loader",
query: {
presets: [
["env", {
"targets": {
ie: 9,
firefox: 30,
chrome: 50,
},
}],
],
},
},
],
},
plugins: [
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.UglifyJsPlugin(),
],
devtool: "source-map",
};
webpack(config, (err, stats) => {
console.log(stats.toString({colors: true}));
callback();
});
});
gulp.task("build-css", () => {
const src = path.resolve("src", "css");
const dist = path.resolve("dist", "css");
const options = {
// nested, expanded, compact, compressed
outputStyle: "compressed",
};
gulp.src(path.join(src, "**", "*.s[ac]ss"))
.pipe(sass(options))
.pipe(gulp.dest(dist));
});