-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
113 lines (96 loc) · 2.41 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
const gulp = require('gulp')
const browserSync = require('browser-sync')
const map = require('map-stream')
const source = require('vinyl-source-stream')
const pug = require('gulp-pug')
const layout = require('gulp-layout')
const markdown = require('gulp-markdown')
const highlight = require('highlight.js')
const less = require('gulp-less')
const postcss = require('gulp-postcss')
const cssnext = require('postcss-cssnext')
const browserify = require('browserify')
const babelify = require('babelify')
const pugOptions = {
pretty: false
}
const markedOptions = {
highlight: (code) => highlight.highlightAuto(code).value
}
const lessOptions = {}
const cssnextOptions = {
browsers: '> 1% in JP' // 日本でシェア1%以上
}
const browserifyOptions = {
debug: true
}
const babelOptions = {
presets: [
['env', {
targets: {
browsers: '> 1% in JP'
}
}]
]
}
gulp.task('build:pug',
async () => gulp.src(['src/**/[^_]*.pug'])
.pipe(pug(pugOptions))
.pipe(gulp.dest('dist/'))
)
gulp.task('build:markdown',
async () => gulp.src(['src/**/*.md'])
.pipe(markdown(markedOptions))
.pipe(layout({
title: 'markdown',
layout: 'src/_md-template.pug',
}))
.pipe(gulp.dest('dist/'))
)
gulp.task('build:less',
async () => gulp.src(['src/**/[^_]*.less'])
.pipe(less(lessOptions))
.pipe(postcss([
cssnext(cssnextOptions)
]))
.pipe(gulp.dest('dist/'))
)
gulp.task('build:js', async () => {
const processor = (file) => {
browserify(file.path, browserifyOptions)
.transform(babelify, babelOptions)
.bundle()
.on('error', (err) => console.error(`Error: ${err.message}`))
.pipe(source(file.path.replace(file.base, '')))
.pipe(gulp.dest('dist/'))
}
return gulp.src(['src/**/[^_]*.js'])
.pipe(map(a => processor(a)))
})
gulp.task('build', gulp.parallel(
'build:pug',
'build:markdown',
'build:less',
'build:js'
))
gulp.task('watch',
gulp.series('build', async () => {
browserSync({
server: {
baseDir: './dist'
}
})
gulp.watch([
'src/**/*.pug',
'src/**/*.md',
'src/**/*.less',
'src/**/*.js'
], gulp.series(
'build',
async () => {
console.log('build complete')
browserSync.reload()
}
))
})
)