-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
92 lines (80 loc) · 2.42 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
const autoprefixer = require('autoprefixer'),
clean = require('gulp-clean-css'),
del = require('del'),
gulp = require('gulp'),
path = require('path'),
postcss = require('gulp-postcss'),
RevAll = require('gulp-rev-all'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
shell = require('gulp-shell'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify');
const sourceRoot = '/HashRev/build',
scripts = ['build/**/js/*.js', '!build/**/bootstrap/*.js'];
const app = {
scripts: scripts,
styles: ['build/**/scss/*.scss'],
copies: ['build/**/*.html'],
build: 'build',
dist: 'dist'
};
gulp.task('scripts', function () {
return gulp.src(app.scripts)
.pipe(sourcemaps.init())
.pipe(uglify({mangle: false}))
.pipe(sourcemaps.write('.', {
includeContent: false,
sourceRoot: sourceRoot
}))
.pipe(gulp.dest(app.dist));
});
gulp.task('styles', function () {
return gulp.src(app.styles)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(postcss([
autoprefixer({
browsers: ['> 1% in CN']
})
]))
.pipe(clean())
.pipe(rename(function (path) {
path.dirname = path.dirname.replace('scss', 'css');
}))
.pipe(sourcemaps.write('.', {
includeContent: false,
sourceRoot: sourceRoot
}))
.pipe(gulp.dest(app.dist));
});
gulp.task('bs', function () {
});
gulp.task('copy', function () {
return gulp.src(app.copies)
.pipe(gulp.dest(app.dist));
});
gulp.task('del', function () {
del([app.build, app.dist]);
});
gulp.task('rev', function () {
var revAll = new RevAll({
dontRenameFile: [/bootstrap\/.+/gi],
replacer: function (fragment, replaceRegExp, newReference, referencedFile) {
fragment.contents = fragment.contents.replace(replaceRegExp, function (matched, $1, $2, $3, $4) {
return ($1 + newReference + $3 + $4).replace(/(\/|\.)scss(\/)?/g, '$1css$2');
});
}
});
return gulp.src('src/**')
.pipe(revAll.revision())
.pipe(gulp.dest(app.build))
.pipe(revAll.manifestFile())
.pipe(gulp.dest(app.build));
});
gulp.task('deploy', ['scripts', 'styles', 'copy']);
gulp.task('default', shell.task([
'gulp del',
'gulp rev',
'gulp deploy'
]));