-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathgulpfile.js
105 lines (87 loc) · 2.59 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
var gulp = require('gulp');
var less = require('gulp-less');
var shell = require('gulp-shell');
var cssnano = require('gulp-cssnano');
var watch = require('gulp-watch');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var rewriteCSS = require('gulp-rewrite-css');
var autoprefixer = require('gulp-autoprefixer');
// Vueify
var fs = require("fs")
var browserify = require('browserify')
var vueify = require('vueify')
var npm_folder = './node_modules';
var vars = {
lib_js: [
// Vue.js
npm_folder+'/vue/dist/vue.js',
// Axios
npm_folder+'/axios/dist/axios.js'
]
};
/*
* LESS FILES COMPILATION
*/
// Create a minify min.css file compiled from the `src\less` folder
gulp.task('minify_front', function() {
return gulp.src('src/less/front.less')
.pipe(less())
.pipe(cssnano({
'postcss-minify-font-values': true
}))
.pipe(autoprefixer({
browsers:"> 1%, last 2 versions, Safari >= 8"
}))
.pipe(rename({basename: 'front', suffix: '.min'}))
.pipe(gulp.dest('dist/css/'));
});
// Create a decompressed .css file compiled from the `src\less` folder
gulp.task('front', function() {
return gulp.src('src/less/front.less')
.pipe(less())
.pipe(autoprefixer({
browsers:"> 1%, last 2 versions, Safari >= 8"
}))
.pipe(rename({basename: 'front'}))
.pipe(gulp.dest('dist/css/'));
});
/*
* JS FILES COMPILATION
*/
// Create a minify .min.js file compiled from the `node_modules` folder
gulp.task('npm_js', function() {
return gulp.src(vars.lib_js)
.pipe(concat('app.js'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist/js/'));
});
// Create a minify .min.js file compiled from the `src\js\*.js` files
gulp.task('app_js', function() {
// return gulp.src('src/js/**/*.js')
// .pipe(concat('global.js'))
// .pipe(uglify())
// .pipe(rename({suffix: '.min'}))
// .pipe(gulp.dest('dist/js/'));
return browserify('src/js/main.js')
.transform(vueify)
.bundle()
.pipe(fs.createWriteStream("dist/js/vueapp.min.js"))
});
/*
* WATCH TASKS
*/
gulp.task('watch',['minify_front','front','app_js'], function() {
gulp.watch('src/**/*.less', ['minify_front', 'front']);
gulp.watch('src/js/**/*.js', ['app_js']);
gulp.watch('src/js/**/*.vue', ['app_js']);
});
gulp.task('default', [
'front',
'minify_front',
'app_js',
'npm_js'
]);