-
Notifications
You must be signed in to change notification settings - Fork 13
/
gulpfile.js
95 lines (87 loc) · 2.85 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
92
93
94
95
'use strict'
const gulp = require('gulp');
const babel = require('gulp-babel');
const babelify = require('babelify');
const browserify = require('browserify');
const browserifyshim = require('browserify-shim');
const rename = require('gulp-rename');
const jshint = require('gulp-jshint');
const replace = require('gulp-replace');
const insert = require('gulp-insert');
const template = require('gulp-template');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const collapse = require('bundle-collapser/plugin');
const gutil = require('gulp-util');
const streamify = require('gulp-streamify');
const concat = require('gulp-concat');
let pack = require('./package.json');
let header = "/*!\n" +
" * wx-chart.js\n" +
" * Chart for WeiXin application\n" +
" * Version: {{ version }}\n" +
" *\n" +
" * Copyright 2016 Jone Casper\n" +
" * Released under the MIT license\n" +
" * https://github.com/xch89820/wx-chart/blob/master/LICENSE.md\n" +
" */\n";
gulp.task('build',function(){
// Bundled library
let bundled = browserify('./src/wx-chart.js', {
standalone: 'WxChart',
"transform": [
[
"babelify"
],
[
"browserify-replace",
{
"replace": [
{
"from": /__GLOBAL__DEBUG__WX__/g,
"to": false
},
{
"from": /__GDEBUG__/g,
"to": false
}
]
}
],
// [
// "browserify-shim"
// ]
]})
// .transform(browserifyshim)
//.plugin(collapse)
.bundle()
.pipe(source('wx-chart.js'))
.pipe(streamify(babel({
presets: ['es2015',"stage-0"]
})))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(insert.prepend(header))
.pipe(streamify(replace('{{ version }}', pack.version)))
//.pipe(streamify(jshint()))
//.pipe(jshint.reporter('default'))
.pipe(gulp.dest('dist'))
.pipe(streamify(uglify()))
.pipe(insert.prepend(header))
.pipe(streamify(replace('{{ version }}', pack.version)))
.pipe(streamify(concat('wx-chart.min.js')))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist'));
return bundled;
});
gulp.task('jshint',function(){
return gulp.src('src/**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
gulp.task('default',function(){
gulp.watch('src/**/*.js',['js']);
});