-
Notifications
You must be signed in to change notification settings - Fork 72
/
gulpfile.js
77 lines (71 loc) · 1.84 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
const pkg = require('./package.json');
const path = require('path');
const gulp = require('gulp');
const sass = require('sass');
const rename = require('gulp-rename');
const postcss = require('gulp-postcss');
const webpack = require('webpack-stream');
const through = require('through2');
// a custom pipeable step to transform Sass to CSS
function compileSass() {
return through.obj((vinylFile, encoding, callback) => {
const transformedFile = vinylFile.clone();
sass.render(
{
data: transformedFile.contents.toString(),
includePaths: ['css/'],
},
(err, result) => {
if (err) {
console.log(vinylFile.path);
console.log(err.formatted);
} else {
transformedFile.extname = '.css';
transformedFile.contents = result.css;
callback(null, transformedFile);
}
}
);
});
}
gulp.task('js', () =>
gulp
.src(['js/main.js'])
.pipe(
webpack({
mode:
process.env.NODE_ENV === 'production' ? 'production' : 'development',
performance: {
hints: false,
},
resolve: {
modules: ['js', 'node_modules'],
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /(node_modules)/,
},
],
},
})
)
// .pipe(rename('main.js'))
.pipe(gulp.dest('./dist'))
);
gulp.task('css', () =>
gulp
.src(['css/main.scss'])
.pipe(compileSass())
.pipe(postcss())
.pipe(rename('main.css'))
.pipe(gulp.dest('./dist'))
);
gulp.task('build', gulp.parallel('js', 'css'));
gulp.task('default', () => {
gulp.watch(['js/**.*', 'js/*/**.*'], gulp.series('js'));
gulp.watch(['css/**.*', 'css/*/**.*'], gulp.series('css'));
gulp.parallel('js', 'css')();
});