-
Notifications
You must be signed in to change notification settings - Fork 72
/
gulpfile.babel.js
175 lines (151 loc) · 4.06 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import path from "path";
import gulp from "gulp";
import gutil from "gulp-util";
import notifier from "node-notifier";
import { create as browserSyncCreate } from "browser-sync";
import webpack from "webpack";
import nodeExternals from "webpack-node-externals";
import eslint from "gulp-eslint";
import filter from "gulp-filter";
import rename from "gulp-rename";
import shell from "gulp-shell";
import runSequence from "run-sequence";
import assign from "lodash.assign";
const browserSync = browserSyncCreate();
browserSync.use({
plugin() {},
hooks: {
"client:js":
'___browserSync___.socket.on("disconnect", window.close.bind(window));'
}
});
const sharedWebpackConfig = {
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /dist|public|node_modules/,
loader: "babel-loader"
}
]
},
resolve: {
extensions: [".js", ".jsx"]
},
watch: false
};
const libWebpackConfig = assign({}, sharedWebpackConfig, {
mode: "production",
entry: path.join(__dirname, "./src/index.js"),
output: {
path: path.join(__dirname, "./lib"),
filename: "react-stonecutter.js",
library: "reactStonecutter",
libraryTarget: "commonjs2"
},
externals: [nodeExternals()]
});
const demoWebpackConfig = assign({}, sharedWebpackConfig, {
mode: "none",
entry: path.join(__dirname, "./demo/src/main.jsx"),
output: {
path: path.join(__dirname, "./demo/public"),
filename: "demo.js"
}
});
const devCompiler = webpack([libWebpackConfig, demoWebpackConfig]);
gulp.task("webpack", done => {
let firstTime = true;
devCompiler.watch(
{
aggregateTimeout: 100
},
(err, stats) => {
if (err) {
notifier.notify({ title: "Webpack Error", message: err });
throw new gutil.PluginError("webpack", err);
}
const jsonStats = stats.toJson();
if (jsonStats.errors.length > 0) {
notifier.notify({
title: "Webpack Error",
message: jsonStats.errors[0]
});
} else if (jsonStats.warnings.length > 0) {
notifier.notify({
title: "Webpack Warning",
message: jsonStats.warnings[0]
});
}
gutil.log(
gutil.colors.cyan("[webpack]"),
stats.toString({
chunks: false,
version: false,
colors: true
})
);
browserSync.reload();
if (firstTime) {
firstTime = false;
done();
}
}
);
});
gulp.task("browser-sync", ["webpack", "demo-html-css"], () => {
browserSync.init({
notify: false,
ghostMode: false,
server: {
baseDir: "demo/public"
}
});
});
gulp.task("demo-html-css", () => {
const sliderCssFilter = filter("node_modules/rc-slider/assets/index.css", {
restore: true
});
return gulp
.src(["demo/src/*.@(html|css)", "node_modules/rc-slider/assets/index.css"])
.pipe(sliderCssFilter)
.pipe(rename("rc-slider.css"))
.pipe(sliderCssFilter.restore)
.pipe(gulp.dest("demo/public"))
.pipe(browserSync.reload({ stream: true }));
});
gulp.task("watch", () => {
gulp.watch("src/js/**/*", e => {
const watchPath = gutil.colors.magenta(
e.path.substring(e.path.lastIndexOf("/") + 1)
);
const type = gutil.colors.cyan(`${e.type}...`);
gutil.log(`${watchPath} ${type}`);
});
gulp.watch("demo/src/*.@(html|css)", ["demo-html-css"]);
});
gulp.task("gh-pages-start", shell.task(["git stash", "git checkout gh-pages"]));
gulp.task("copy-demo-to-root", () =>
gulp.src("./demo/public/**/*").pipe(gulp.dest("./"))
);
gulp.task(
"gh-pages-end",
shell.task([
"git add index.html demo.js *.css",
"git commit --amend --no-edit",
"git push origin gh-pages --force",
"git checkout master",
"git stash apply"
])
);
gulp.task("gh-pages", done => {
runSequence("gh-pages-start", "copy-demo-to-root", "gh-pages-end", done);
});
gulp.task("lint", () =>
gulp
.src(["src/**/*.js*(x)", "demo/src/**/*.js*(x)", "test/**/*.js"])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
gulp.task("default", ["browser-sync", "watch"]);