Skip to content

Commit 63d847b

Browse files
authored
feat: support weapp (#372)
1 parent dbad989 commit 63d847b

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

gulpfile.babel.js

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import clean from 'gulp-clean';
1111
import concat from 'gulp-concat';
1212
import rename from 'gulp-rename';
1313
import uglify from 'gulp-uglify';
14+
import insert from 'gulp-insert';
1415
import source from 'vinyl-source-stream';
16+
import streamify from 'gulp-streamify';
1517
import browserify from 'browserify';
1618
import browserSync from 'browser-sync';
1719
import babel from 'gulp-babel';
@@ -54,43 +56,50 @@ gulp.task('clean-dist', () => {
5456
));
5557
});
5658

57-
gulp.task('browserify', ['clean-dist'], () => {
58-
const bundle = browserify({
59+
// 编译浏览器版本
60+
gulp.task('bundle-browser', () => {
61+
return browserify({
5962
entries: './src/index.js',
6063
standalone: 'AV'
61-
});
62-
return bundle.bundle()
63-
.pipe(source('av-es6.js'))
64-
.pipe(gulp.dest('dist'));
65-
});
66-
67-
// 编译浏览器版本
68-
gulp.task('babel-browser', ['browserify'], () => {
69-
return gulp.src('dist/av-es6.js')
64+
}).bundle()
65+
.pipe(source('av.js'))
7066
// .pipe(sourcemaps.init())
71-
.pipe(babel({
67+
.pipe(streamify(babel({
7268
compact: false
73-
}))
74-
.pipe(concat('av.js'))
69+
})))
7570
// .pipe(sourcemaps.write("."))
7671
.pipe(gulp.dest('dist'));
7772
});
7873

79-
gulp.task('uglify', ['babel-browser'], () => {
74+
gulp.task('uglify', ['bundle-browser', 'bundle-weapp'], () => {
8075
return gulp.src([
81-
'dist/av.js'
76+
'dist/av.js',
77+
'dist/av-weapp.js'
8278
])
8379
.pipe(uglify())
8480
.pipe(rename((path) => {
85-
// path.basename += '-mini';
86-
path.basename = 'av-min';
81+
path.basename += '-min';
8782
}))
8883
.pipe(gulp.dest('dist'));
8984

9085
// return gulp.src(['dist/av-es5.js'])
9186
// .pipe(clean());
9287
});
9388

89+
gulp.task('bundle-weapp', () =>
90+
browserify({
91+
entries: './src/index-weapp.js',
92+
standalone: 'AV'
93+
})
94+
.bundle()
95+
.pipe(source('av-weapp.js'))
96+
.pipe(streamify(babel({
97+
compact: false
98+
})))
99+
.pipe(streamify(insert.prepend('var exports = module.exports = {};')))
100+
.pipe(gulp.dest('dist'))
101+
)
102+
94103
gulp.task('clean-node', () => {
95104
return gulp.src(['dist/node/**/*.*'])
96105
.pipe(clean({force: true}));
@@ -130,8 +139,8 @@ gulp.task('upload', () => {
130139
gulp.task('release', [
131140
// 生成浏览器版本
132141
'clean-dist',
133-
'browserify',
134-
'babel-browser',
142+
'bundle-browser',
143+
'bundle-weapp',
135144
'uglify',
136145
// 生成 node 版本
137146
'clean-node',
@@ -141,9 +150,7 @@ gulp.task('release', [
141150
// 浏览器开发时使用
142151
gulp.task('dev', [
143152
'clean-dist',
144-
'browserify',
145-
'babel-browser',
146-
'uglify',
153+
'bundle-browser',
147154
'babel-demo'
148155
], () => {
149156
browserSync({

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@
4040
"gulp-clean": "^0.3.1",
4141
"gulp-concat": "^2.4.3",
4242
"gulp-eslint": "^0.13.2",
43+
"gulp-insert": "^0.5.0",
4344
"gulp-rename": "^1.2.0",
45+
"gulp-streamify": "^1.0.2",
4446
"gulp-uglify": "^1.0.2",
4547
"jsdoc": "~3.4.0",
4648
"mocha": "^3.0.0",
4749
"nyc": "^8.1.0",
4850
"should": "^11.1.0",
49-
"vinyl-source-stream": "^1.1.0"
51+
"vinyl-source-stream": "^1.1.0",
52+
"weapp-polyfill": "github:leancloud/weapp-polyfill#0368089"
5053
},
5154
"license": "MIT",
5255
"author": {

src/index-weapp.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require('weapp-polyfill').polyfill(window);
2+
3+
module.exports = require('./index');

0 commit comments

Comments
 (0)