-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathgulpfile.js
123 lines (107 loc) · 3.2 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
113
114
115
116
117
118
119
120
121
122
123
var gulp = require('gulp');
var gutil = require('gulp-util');
var gulpIgnore = require('gulp-ignore');
var rename = require('gulp-rename');
var watch = require('gulp-watch');
var less = require('gulp-less');
var del = require('del');
var zip = require('gulp-zip');
var minifyCSS = require('gulp-clean-css'); // gulp-minify-css
var cssnano = require('gulp-cssnano');
var purify = require('gulp-purifycss');
var runSequence = require('run-sequence');
var LessPluginAutoPrefix = require('less-plugin-autoprefix');
var autoprefix= new LessPluginAutoPrefix({ browsers: ["last 2 versions"] });
//var gulpLoadPlugins = require('gulp-load-plugins');
//plugins = gulpLoadPlugins();
var path = require('path');
var startDevServer = require('./server').start;
var build = require('./server').build;
//var buildDest = require('./server.config.json').buildFolder;
var buildDest = require('./server').buildPathDestination;
var deployDest = require('./server').deployPathDestination;
var templateFile = './src/Template.qextmpl';
var lessFiles = './src/**/*.less';
var cssFiles = './src/**/*.css';
var jsFiles = './**/*.js';
var name = path.basename(__dirname);
var ccsnanoConfig = {
discardComments: {
removeAll: true
},
discardUnused: true,
discardEmpty: true,
// mergeLonghand: true,
// reduceIdents: true
};
gulp.task('build', function(callback){
build(function(err, stats){
if(err) {
return callback(err);
}
callback();
});
});
gulp.task('devServer', function(callback){
startDevServer(function(err, server){
if(err) {
return callback(err);
}
callback();
});
});
gulp.task('qext', function () {
return gulp.src(templateFile)
.pipe(rename(name+'.qext'))
.pipe(gulp.dest(buildDest));
});
gulp.task('less2css', function(){
return gulp.src(lessFiles)
.pipe(less({
plugins: [autoprefix]
}))
//.pipe(minifyCSS({keepSpecialComments : 0}))
.pipe(cssnano(ccsnanoConfig))
.pipe(gulp.dest(buildDest));
});
gulp.task('purifycss', function(){
return gulp.src('./build/*.css')
.pipe(purify(['./src/**/*.js']))
.pipe(gulp.dest(buildDest));
});
gulp.task('css', function(){
return gulp.src(cssFiles)
//.pipe(minifyCSS({keepSpecialComments : 0}))
.pipe(cssnano(ccsnanoConfig))
.pipe(gulp.dest(buildDest));
});
gulp.task('watch', function(){
gulp.watch(templateFile, ['qext']);
gulp.watch(lessFiles, ['less2css']);
gulp.watch(cssFiles, ['css']);
});
gulp.task('remove-build-zip', function(callback){
del.sync(['build/' + name + '.zip']);
callback();
});
gulp.task('zip-build', function(){
return gulp.src('build/**/*')
.pipe(zip(name + '.zip'))
.pipe(gulp.dest('build'));
});
gulp.task('deploy-assets', function(){
return gulp.src("assets/**/*").pipe(gulp.dest(deployDest));
});
gulp.task('deploy', function(){
return gulp.src(buildDest + "/**/*").pipe(gulp.dest(deployDest));
});
gulp.task('development', ['qext', 'less2css', /*'css',*/ 'deploy-assets', 'watch', 'devServer']);
gulp.task('production', function(callback) {
runSequence(['qext', 'less2css', /*'css',*/ 'purifycss', 'remove-build-zip'],
'build',
'zip-build',
'deploy-assets',
'deploy'
);
});
//gulp.task('default', ['production']);