-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathgulpfile.js
76 lines (67 loc) · 2.06 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
const { src, dest, parallel, watch } = require('gulp'),
rollup = require('gulp-better-rollup'),
babel = require('rollup-plugin-babel'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
uglify = require('gulp-uglify-es').default,
connect = require('gulp-connect'),
rootImport = require('rollup-plugin-root-import'),
nodeResolve = require('rollup-plugin-node-resolve'),
commonjs = require('rollup-plugin-commonjs');
sass.compiler = require('sass');
const serverTask = (done) => {
connect.server({
root: '',
host: '0.0.0.0',
livereload: true
});
done();
};
const stylesTask = () => src('src/sass/app.scss')
.pipe(sass({
includePaths: [
'node_modules',
require('path').resolve(__dirname, 'node_modules')
]
}))
.pipe(autoprefixer('last 2 version'))
.pipe(dest('dist/css'))
.pipe(connect.reload());
const scriptsTask = () => src('src/javascripts/index.js')
.pipe(rollup({
rollup: require('rollup'),
// There is no `input` option as rollup integrates into the gulp pipeline
plugins: [
nodeResolve({
mainFields: ['module', 'main', 'browser']
}),
commonjs({
include: [/node_modules/]
}),
rootImport({
root: `src/javascripts`,
extensions: '.js'
}),
babel()
]
}, {
// Rollups `sourcemap` option is unsupported. Use `gulp-sourcemaps` plugin instead
format: 'umd',
}))
.pipe(dest('dist/js'))
.pipe(connect.reload());
const htmlTask = () => src('*.html').pipe(connect.reload());
const watchTask = (done) => {
watch('*.html', htmlTask);
watch('src/javascripts/**', scriptsTask);
watch('src/sass/**', stylesTask);
done();
};
const stylesDist = () => src('dist/css/app.css')
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(dest('dist/css'));
const scriptsDist = () => src('dist/js/index.js')
.pipe(uglify())
.pipe(dest('dist/js/'));
exports.default = parallel(watchTask, serverTask);
exports.build = parallel(stylesDist, scriptsDist);