This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
67 lines (61 loc) · 1.73 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
var rulePrefix = '.antd-ns'
var sourcePath = './node_modules/antd/dist/antd.css'
var targetFolder = './build/static/css/'
var targetFile = 'antd-namespaced.min.css'
/****/
var gulp = require('gulp');
var rename = require('gulp-rename');
var postcss = require('gulp-postcss');
var cssnano = require('cssnano');
var prefixwrap = require('postcss-prefixwrap');
var dom = require('gulp-dom');
gulp.task('build-namespaced-css', function() {
return gulp
.src(sourcePath)
.pipe(
postcss([
prefixwrap(
rulePrefix,
{
ignoredSelectors: [
':root',
/^\.zoom-big-fast(.+)$/,
/^\.ant(.+)$/,
/^\.slide-(.+)$/,
]
}
),
// Minify after prefixwrap
cssnano({ preset: 'default' }),
])
)
.pipe(rename(targetFile))
.pipe(gulp.dest(targetFolder))
});
gulp.task('modify-html', function() {
return gulp.src('./build/index.html')
.pipe(dom(function () {
var srcs = this.querySelectorAll('[src^="/"], [href^="/"]');
srcs.forEach(element => {
var attr = element.getAttribute('src') ? 'src' : 'href';
element.setAttribute(attr, element[attr].replace('/', ''));
});
return this;
}))
.pipe(rename('index.html'))
.pipe(gulp.dest('./build/'));
});
gulp.task('modify-html-fixed', function() {
return gulp.src('./build/index.html')
.pipe(dom(function () {
this.querySelector('link[rel="stylesheet"][href*="main"]').setAttribute('href', 'static/css/antd-namespaced.min.css');
var srcs = this.querySelectorAll('[src^="/"], [href^="/"]');
srcs.forEach(element => {
var attr = element.getAttribute('src') ? 'src' : 'href';
element.setAttribute(attr, element[attr].replace('/', ''));
});
return this;
}))
.pipe(rename('index-fixed.html'))
.pipe(gulp.dest('./build/'));
});