-
Notifications
You must be signed in to change notification settings - Fork 19
/
gulpfile.js
93 lines (83 loc) · 2.72 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
// #####################################################################################################################
// #IMPORTS#
var gulp = require('gulp');
var gutil = require('gulp-util');
var gulpif = require('gulp-if');
var autoprefixer = require('autoprefixer');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var minifyCss = require('gulp-clean-css');
var sourcemaps = require('gulp-sourcemaps');
// var eslint = require('gulp-eslint');
var webpack = require('webpack');
var argv = require('minimist')(process.argv.slice(2)); // eslint-disable-line
// #####################################################################################################################
// #SETTINGS#
var options = {
debug: argv.debug,
};
var PROJECT_ROOT = __dirname + '/djangocms_icon/static/djangocms_icon';
var PROJECT_PATH = {
js: PROJECT_ROOT + '/js',
sass: PROJECT_ROOT + '/sass',
css: PROJECT_ROOT + '/css',
};
var PROJECT_PATTERNS = {
js: [
PROJECT_PATH.js + '/*.js',
'!' + PROJECT_PATH.js + '/dist/*.js',
],
sass: [
PROJECT_PATH.sass + '/**/*.{scss,sass}',
],
icons: [
PROJECT_PATH.icons + '/src/*.svg',
],
};
var webpackBundle = function (opts) {
var webpackOptions = opts || {};
webpackOptions.PROJECT_PATH = PROJECT_PATH;
webpackOptions.debug = options.debug;
return function (done) {
var config = require('./webpack.config')(webpackOptions);
webpack(config, function (err, stats) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
gutil.log('[webpack]', stats.toString({ maxModules: Infinity, colors: true, optimizationBailout: true }));
if (typeof done !== 'undefined' && (!opts || !opts.watch)) {
done();
}
});
};
};
gulp.task('bundle:watch', webpackBundle({ watch: true }));
gulp.task('bundle', webpackBundle());
gulp.task('sass', function() {
gulp
.src(PROJECT_PATTERNS.sass)
.pipe(gulpif(options.debug, sourcemaps.init()))
.pipe(sass())
.on('error', function(error) {
gutil.log(gutil.colors.red('Error (' + error.plugin + '): ' + error.messageFormatted));
})
.pipe(
postcss([
autoprefixer({
cascade: false,
}),
])
)
.pipe(
minifyCss({
rebase: false,
})
)
.pipe(gulpif(options.debug, sourcemaps.write()))
.pipe(gulp.dest(PROJECT_PATH.css));
});
gulp.task('watch', ['sass'], function () {
gulp.start('bundle:watch');
gulp.watch(PROJECT_PATTERNS.sass, ['sass']);
});
gulp.task('default', ['watch']);