-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
91 lines (84 loc) · 2.47 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
'use strict'
const gulp = require('gulp')
const uglify = require('gulp-uglify')
const sourcemaps = require('gulp-sourcemaps')
const header = require('gulp-header')
const rename = require('gulp-rename')
const clean = require('gulp-clean')
const beautify = require('gulp-beautify');
const stripDebug = require('gulp-strip-debug');
const rollup = require('rollup')
const babel = require('rollup-plugin-babel')
const resolve = require('rollup-plugin-node-resolve')
const pkg = require('./package.json')
const FILE_ADDR = './dist/';
const DEV_ADDR = './example/static/'
let rollupOpt = {
// 入口文件
input: './index.js',
plugins: [
resolve(),
babel({
babelrc: false,
presets: [['env', { modules: false }]],
// exclude: 'node_modules/**' // only transpile our source code
})
]
}
const banner = () => {
return [
'/**!',
' * <%= pkg.name %> - v<%= pkg.version %>',
' * <%= pkg.description %>',
' *',
' * <%= new Date( Date.now() ) %>',
' * <%= pkg.license %> (c) <%= pkg.author %>',
'*/',
''
].join('\n')
}
gulp.task('structure', function(){
// 使用rollup构建
return rollup.rollup(rollupOpt)
.then(function(bundle){
bundle.write({
format: 'umd',
name: 'Ajax',
file: FILE_ADDR + 'ajax.js',
}).then(function(){
gulp.src(FILE_ADDR + './ajax.js')
.pipe(beautify({indent_size: 4}))
.pipe(gulp.dest(FILE_ADDR))
.pipe(stripDebug())
.pipe(sourcemaps.init())
// 压缩
.pipe(uglify())
.pipe(header(banner(), { pkg: pkg }))
// 产出的压缩的文件名
.pipe(rename('ajax.min.js'))
// 生成 sourcemap
.pipe(sourcemaps.write(''))
.pipe(gulp.dest(FILE_ADDR))
})
})
})
gulp.task('dev_structure', function(){
// 使用rollup构建
return rollup.rollup(rollupOpt)
.then(function(bundle){
bundle.write({
format: 'umd',
name: 'Ajax',
file: DEV_ADDR + 'ajax.js',
}).then(function(){
gulp.src(DEV_ADDR + 'ajax.js')
.pipe(beautify({indent_size: 4}))
.pipe(gulp.dest(DEV_ADDR))
})
})
})
gulp.task("dev", ['dev_structure'], function(){
gulp.watch('./src/*.js',['dev_structure'])
})
gulp.task("build", ['structure'], function(){
})