Skip to content

Commit 2ea5a98

Browse files
einsqingdplewis
authored andcommitted
Support for Wechat applet (#874)
* Support for Wechat applet * fix eslint and localStorage * fix regenerator-runtime https://blog.csdn.net/xubaifu1997/article/details/90605683 * support file downloadAjax * support liveQuery * Add weapp.js to distribution * support LocalDatastore * Update readme and remove wx.Parse
1 parent 8b61d04 commit 2ea5a98

16 files changed

+498
-201
lines changed

.eslintrc.json

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"es6": true
77
},
88
"parser": "babel-eslint",
9+
"globals": {
10+
"wx": true
11+
},
912
"plugins": [
1013
"flowtype"
1114
],

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ const AsyncStorage = require('react-native').AsyncStorage;
4545
Parse.setAsyncStorage(AsyncStorage);
4646
```
4747

48+
For WeChat miniprogram, include `'parse/weapp'`:
49+
```js
50+
// In a WeChat miniprogram
51+
const Parse = require('parse/weapp');
52+
```
53+
If you want to use a pre-compiled file, you can fetch it from [unpkg](https://unpkg.com). The development version is available at [https://unpkg.com/parse/dist/parse.weapp.js](https://unpkg.com/parse/dist/parse.weapp.js), and the minified production version is at [https://unpkg.com/parse/dist/parse.weapp.min.js](https://unpkg.com/parse/dist/parse.weapp.min.js).
54+
4855
For TypeScript applications, install `'@types/parse'`:
4956
```
5057
$ npm install @types/parse

build_releases.sh

+4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ rm -rf dist lib
88

99
echo "Browser Release:"
1010
PARSE_BUILD=browser gulp compile
11+
echo "Weapp Release:"
12+
PARSE_BUILD=weapp gulp compile
1113
echo "Node.js Release:"
1214
PARSE_BUILD=node gulp compile
1315
echo "React Native Release:"
1416
PARSE_BUILD=react-native gulp compile
1517
echo "Bundling and minifying for CDN distribution:"
1618
gulp browserify
19+
gulp browserify-weapp
1720
gulp minify
21+
gulp minify-weapp

gulpfile.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ var PRESETS = {
2323
'browser': [["@babel/preset-env", {
2424
"targets": "> 0.25%, not dead"
2525
}], '@babel/preset-react'],
26+
'weapp': [["@babel/preset-env", {
27+
"targets": "> 0.25%, not dead"
28+
}], '@babel/preset-react'],
2629
'node': [["@babel/preset-env", {
2730
"targets": { "node": "8" }
2831
}]],
@@ -31,8 +34,10 @@ var PRESETS = {
3134
var PLUGINS = {
3235
'browser': [transformRuntime, '@babel/plugin-transform-flow-comments', '@babel/plugin-proposal-class-properties', 'inline-package-json',
3336
['transform-inline-environment-variables', {'exclude': ['SERVER_RENDERING']}]],
37+
'weapp': [transformRuntime, '@babel/plugin-transform-flow-comments', '@babel/plugin-proposal-class-properties', 'inline-package-json',
38+
['transform-inline-environment-variables', {'exclude': ['SERVER_RENDERING']}]],
3439
'node': ['@babel/plugin-transform-flow-comments', 'inline-package-json', 'transform-inline-environment-variables'],
35-
'react-native': ['@babel/plugin-transform-flow-comments', 'inline-package-json', 'transform-inline-environment-variables'],
40+
'react-native': ['@babel/plugin-transform-flow-comments', 'inline-package-json', 'transform-inline-environment-variables']
3641
};
3742

3843
var DEV_HEADER = (
@@ -90,6 +95,25 @@ gulp.task('browserify', function(cb) {
9095
.pipe(gulp.dest('./dist'));
9196
});
9297

98+
99+
gulp.task('browserify-weapp', function(cb) {
100+
var stream = browserify({
101+
builtins: ['_process', 'events'],
102+
entries: 'lib/weapp/Parse.js',
103+
standalone: 'Parse'
104+
})
105+
.exclude('xmlhttprequest')
106+
.ignore('_process')
107+
.bundle();
108+
stream.on('end', () => {
109+
cb();
110+
});
111+
return stream.pipe(source('parse.weapp.js'))
112+
.pipe(derequire())
113+
.pipe(insert.prepend(DEV_HEADER))
114+
.pipe(gulp.dest('./dist'));
115+
});
116+
93117
gulp.task('minify', function() {
94118
return gulp.src('dist/parse.js')
95119
.pipe(uglify())
@@ -98,6 +122,14 @@ gulp.task('minify', function() {
98122
.pipe(gulp.dest('./dist'))
99123
});
100124

125+
gulp.task('minify-weapp', function() {
126+
return gulp.src('dist/parse.weapp.js')
127+
.pipe(uglify())
128+
.pipe(insert.prepend(FULL_HEADER))
129+
.pipe(rename({ extname: '.min.js' }))
130+
.pipe(gulp.dest('./dist'))
131+
});
132+
101133
gulp.task('watch', function() {
102134
return watch('src/*.js', { ignoreInitial: false, verbose: true })
103135
.pipe(babel({

0 commit comments

Comments
 (0)