123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- const gulp = require('gulp')
- const htmlmin = require('gulp-htmlmin')
- const babel = require('gulp-babel')
- const uglify = require('gulp-uglify')
- const cleanCss = require('gulp-clean-css')
- const clean = require('gulp-clean')
- const gulpif = require('gulp-if')
- const plumber = require('gulp-plumber')
- const size = require('gulp-size')
- const config = require('./tools/config')
- const converter = require('./tools/converter')
- const ifdef = require('./tools/ifdef')
- const minifier = require('./tools/minifier')
- const plugin = require('./tools/plugin')
- const isDev = process.argv.includes('--dev')
- let platform = process.argv[3]
- if (!platform) {
- throw Error('缺少平台信息')
- }
- platform = platform.substr(2)
- gulp.task('clean', () => {
- return gulp.src(`${isDev ? 'dev' : 'dist'}/${platform === 'all' ? '' : platform + '/'}*`, {
- read: false,
- allowEmpty: true
- })
- .pipe(clean())
- })
- function packComp () {
- return gulp.src(['plugins/**/*', 'src/**/*'], {
- nodir: true
- })
-
- .pipe(plumber())
- .pipe(plugin.build(platform))
- .pipe(ifdef(platform))
-
- .pipe(gulpif(file => file.extname === '.wxml', minifier.wxs()))
- .pipe(gulpif(file => file.extname === '.wxml', htmlmin(config.htmlmin)))
- .pipe(gulpif(file => file.extname === '.html', htmlmin(Object.assign({}, config.htmlmin, {
- minifyCSS: true
- }))))
-
- .pipe(gulpif(file => file.extname === '.js' && !file.stem.includes('.min') && (platform !== 'uni-app' || file.relative.includes('static')), babel(config.babel)))
- .pipe(gulpif(file => file.extname === '.js' && !file.stem.includes('.min') && !isDev && (platform !== 'uni-app' || file.relative.includes('static')), uglify(config.uglify)))
-
- .pipe(gulpif(file => file.extname.includes('ss'), cleanCss(config.cleanCss)))
- .pipe(plugin.importCss())
-
- .pipe(gulpif(file => file.extname === '.json', minifier.json()))
-
- .pipe(converter(platform))
- .pipe(gulpif(!isDev, size({
- title: `${platform} 包生成完毕`
- })))
- .pipe(gulp.dest(file => {
- return `${isDev ? 'dev' : 'dist'}/${platform}/${(platform === 'uni-app' && !file.relative.includes('components') && !file.relative.includes('static')) || (platform !== 'uni-app' && isDev) ? 'components/mp-html/' : ''}`
- }))
- }
- gulp.task('build', gulp.series('clean', packComp))
- function packDemo () {
- return gulp.src(['tools/demo/**/*', 'test/content.js'], {
- nodir: true
- })
- .pipe(ifdef(platform))
- .pipe(gulpif(platform !== 'uni-app', converter(platform)))
- .pipe(gulp.dest(`dev/${platform}/`))
- }
- gulp.task('dev', gulp.series('clean', gulp.parallel(packComp, packDemo)))
- gulp.task('watch-demo', () => {
- gulp.watch(['tools/demo/**/*', 'test/content.js']).on('all', (type, file) => {
- console.log(type + ':' + file)
- packDemo()
- })
- })
- gulp.task('watch-comp', () => {
- gulp.watch(['src/**/*', 'src/common/**/*', 'plugins/**/*']).on('all', (type, file) => {
- console.log(type + ':' + file)
- packComp()
- })
- })
- gulp.task('watch', gulp.parallel('watch-demo', 'watch-comp'))
|