forked from TalkingData/iview-weapp
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild-dev.js
92 lines (84 loc) · 2.55 KB
/
build-dev.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 { getProjectPath, cssInjection } = require('./util/projectHelper')
const transformLess = require('./util/transformLess')
const path = require('path')
const through2 = require('through2')
const gulp = require('gulp')
const destDir = getProjectPath('dist')
const babel = require("gulp-babel")
const exampleDestDir = getProjectPath('examples/src')
gulp.task('compile-css', done => {
return gulp
.src(['../src/**/*.less'])
.pipe(
through2.obj(function (file, encoding, next) {
this.push(file.clone())
if (file.path.match(/(\/|\\)style(\/|\\)(.*)\.less$/)
|| file.path.match(/(\/|\\)style\.less$/)
) {
transformLess(file.path)
.then(css => {
file.contents = Buffer.from(css)
file.path = file.path.replace(/\.less$/, '.css')
this.push(file)
next()
})
.catch(e => {
console.error(e)
})
}
else {
next()
}
})
)
.pipe(gulp.dest(destDir))
.pipe(gulp.dest(exampleDestDir))
})
gulp.task('compile-js', () => {
return gulp
.src(['../src/**/*.js'])
.pipe(babel({
"plugins": ["@babel/plugin-proposal-object-rest-spread"],
"presets": [
"@babel/preset-env"
]
}))
.pipe(
through2.obj(function (file, encoding, next) {
this.push(file.clone())
if (
file.path.match(/(\/|\\)style(\/|\\)index\.js/)
) {
const content = file.contents.toString(encoding)
file.contents = Buffer.from(cssInjection(content))
file.path = file.path.replace(/index\.js/, 'css.js')
this.push(file)
next()
}
else {
next()
}
})
)
.pipe(gulp.dest(destDir))
.pipe(gulp.dest(exampleDestDir))
})
gulp.task('copy-static', () => {
return gulp
.src(['../assets/**/*.@(png|svg|jpg)'])
.pipe(gulp.dest(path.join(destDir, 'assets')))
.pipe(gulp.dest(path.join(exampleDestDir, 'assets')))
})
gulp.task('copy-vue', () => {
return gulp
.src(['../src/components/**/*.vue'])
.pipe(gulp.dest(path.join(destDir, 'components')))
.pipe(gulp.dest(path.join(exampleDestDir, 'components')))
})
gulp.task('auto', () => {
gulp.watch('../src/**/*.js', ['compile-js'])
gulp.watch('../assets/**/*.@(png|svg|jpg)', ['copy-static'])
gulp.watch('../src/components/**/*.vue', ['copy-vue'])
gulp.watch('../src/**/*.less', ['compile-css'])
})
gulp.task('default', ['compile-css', 'compile-js', 'copy-vue','copy-static', 'auto'])