-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
executable file
·100 lines (88 loc) · 2.57 KB
/
gulpfile.js
File metadata and controls
executable file
·100 lines (88 loc) · 2.57 KB
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
const gulp = require('gulp');
const gulpAutoprefixer = require('gulp-autoprefixer');
const path = require('path');
const readdirRecursive = require('fs-readdir-recursive');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
let isProduction = false;
const config = {
JS_SOURCE_DIR: './source/js/composite/',
JS_SOURCES: [ './partials/**/*.js', './source/js/composite/**/*.js' ],
JS_OUT_DIR: './dist/js/composite/',
JS_OPTIONS: {
uglify: {
mangle: false,
},
},
SASS_SOURCE_DIR: './source/sass/composite/**/*.scss',
SASS_SOURCES: [ './partials/**/*.scss', './source/sass/**/*.scss' ],
SASS_OUT_DIR: './dist/css/composite/',
};
const jsFiles = readdirRecursive(config.JS_SOURCE_DIR);
const entryPaths = {};
jsFiles.forEach((value) => {
if (value.endsWith('.js')) {
const fileExtLength = 3;
const key = value.substring(0, value.length - fileExtLength);
entryPaths[key] = config.JS_SOURCE_DIR + value;
}
});
const webpackDevConfig = {
entry: entryPaths,
mode: 'development',
output: {
path: path.resolve(__dirname, config.JS_OUT_DIR),
filename: '[name].min.js',
},
};
const webpackProdConfig = {
entry: entryPaths,
mode: 'production',
output: {
path: path.resolve(__dirname, config.JS_OUT_DIR),
filename: '[name].min.js',
},
};
gulp.task('compile-js', () => {
let webpackConfig = webpackDevConfig;
if (isProduction === true) {
webpackConfig = webpackProdConfig;
}
return gulp.src(config.JS_SOURCES)
.pipe(webpackStream(
webpackConfig, webpack
))
.pipe(gulp.dest(config.JS_OUT_DIR));
});
gulp.task('watch-js', () => {
webpackDevConfig.watch = true;
gulp.src(config.JS_SOURCES)
.pipe(webpackStream(
webpackDevConfig, webpack
))
.pipe(gulp.dest(config.JS_OUT_DIR));
});
gulp.task('compile-sass', () => {
gulp.src(config.SASS_SOURCE_DIR)
.pipe(sass({
outputStyle: 'compressed',
})).on('error', sass.logError)
.pipe(rename((filePath) => {
filePath.basename += '.min';
}))
.pipe(gulpAutoprefixer({
browsers: [ 'last 1 version', 'last 2 iOS versions' ],
}))
.pipe(gulp.dest(config.SASS_OUT_DIR));
});
gulp.task('watch-sass', () => {
gulp.watch(config.SASS_SOURCES, [ 'compile-sass' ]);
});
gulp.task('set-production', () => {
isProduction = true;
});
gulp.task('build', [ 'compile-js', 'compile-sass' ]);
gulp.task('grow-build', [ 'set-production', 'compile-js', 'compile-sass' ]);
gulp.task('default', [ 'build', 'watch-js', 'watch-sass' ]);