-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
43 lines (38 loc) · 1.05 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
const path = require('path');
const { src, pipe, dest, watch } = require('gulp');
const rename = require('gulp-rename')
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const cssnano = require('gulp-cssnano');
const gulpIf = require('gulp-if');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
// 编译压缩scss
function scss (cb) {
src('src/scss/iu-toast.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(cssnano())
.pipe(rename({ suffix: '.min' }))
.pipe(dest('./dist'));
cb();
}
// 实时监听编译scss
function watchScss (cb) {
watch('src/*.scss', scss)
cb();
}
// 打包兼容js
function scripts (cb) {
const webpackConfigPath = path.join(process.cwd(), 'webpack.config.js');
const webpackConfig = require(webpackConfigPath);
src('src/js/*.js')
.pipe(gulpIf(webpackConfig, webpackStream(webpackConfig, webpack)))
.pipe(dest('./dist'));
cb();
}
module.exports = {
scss: scss,
scripts: scripts,
watchScss: watchScss
}