-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
113 lines (89 loc) · 2.96 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
var gulp = require('gulp'),
fs = require('fs'),
packageInfo = JSON.parse(fs.readFileSync('./package.json')),
gulpif = require('gulp-if'),
size = require('gulp-size'),
run = require('run-sequence'),
argv = require('yargs').argv,
rename = require('gulp-rename'),
sourcemaps = require('gulp-sourcemaps'),
less = require('gulp-less'),
postcss = require('gulp-postcss'),
doiuse = require('doiuse'),
cssnano = require('gulp-cssnano'),
eslint = require('gulp-eslint'),
webpack = require('webpack-stream'),
browserSync = require('browser-sync').create(),
dss = require('gulp-dss'),
nodeunit = require('gulp-nodeunit');
const ENVIRONMENT = argv.production ? 'production' : 'development';
console.log('\x1b[33m%s %s\x1b[0m\n ⇒ %s', ' ',
ENVIRONMENT.toUpperCase(),
packageInfo.name + ' v' + packageInfo.version);
console.log('\x1b[36m%s %s\x1b[0m\n ⇒ %s', ' ',
'Browsers:',
packageInfo.browserslist);
gulp.task('less', () => {
return gulp.src('./src/less/main.less')
.pipe(gulpif(ENVIRONMENT === 'development', sourcemaps.init()))
.pipe(less())
.pipe(postcss())
.pipe(cssnano({ discardComments: { removeAll: true }}))
.pipe(gulpif(ENVIRONMENT === 'development', sourcemaps.write()))
.pipe(postcss([doiuse(require('./doiuse.config.js'))]))
.pipe(rename('muilessium.min.css'))
.pipe(size({ showFiles: true }))
.pipe(gulp.dest('./dist/css'))
.pipe(browserSync.stream());
});
gulp.task('js', () => {
return gulp.src('./src/js/main.js')
.pipe(webpack(require('./webpack.config.js')[ENVIRONMENT]))
.pipe(rename('muilessium.min.js'))
.pipe(gulp.dest('./dist/js'))
.pipe(browserSync.stream());
});
gulp.task('lint-js', () => {
return gulp.src('./src/**/*.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('dss', () => {
return gulp.src('./src/less/components/*.less')
.pipe(dss(require('./dss.config.js')))
.pipe(gulp.dest('./dist'))
.pipe(browserSync.stream());
});
gulp.task('test', () => {
return gulp.src('./test/utils/*.js')
.pipe(nodeunit());
});
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: './dist'
}
});
gulp.watch([
'./src/less/*.less',
'./src/less/components/*.less'
], ['less', 'dss']);
gulp.watch([
'./src/js/*.js',
'./src/js/*/*.js'
], ['js']);
gulp.watch([
'./src/dss/index.handlebars'
], ['dss']);
});
gulp.task('default', () => {
if (ENVIRONMENT === 'production') {
run('less', 'lint-js', 'test', 'js', 'dss');
} else {
run('less', 'js', 'dss');
}
});
gulp.task('server', () => {
run('default', 'browser-sync');
});