-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
49 lines (43 loc) · 1.18 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
const { parallel, series, src, dest } = require('gulp');
const superstatic = require('superstatic');
const browserify = require('browserify');
const fs = require('fs');
const ejs = require('ejs');
function checkDistFolder(cb) {
fs.access('dist', fs.constants.F_OK, (err) => {
if (err) {
// distフォルダが存在しない場合は作成
fs.mkdirSync('dist');
}
cb();
});
}
function javascript(cb) {
const b = browserify({
ignoreMissing : true
});
b.add('./src/index.js');
b.bundle((error, compiled) => {
if (error) console.log(error)
fs.writeFile("./dist/index.js", compiled, cb);
});
}
function html(cb) {
ejs.renderFile("./src/index.ejs", {}, {}, function(err, str){
fs.writeFile("./dist/index.html", str, cb);
});
}
function css() {
return src('./src/*.css')
.pipe(dest('dist/'));
}
function serve() {
superstatic.server({
port:3000,
config: {
public: "./dist/"
},
}).listen();
}
exports.build = series(checkDistFolder, parallel(javascript, html, css));
exports.serve = serve;