diff --git a/packages/discuz-sdk/.gitignore b/packages/discuz-sdk/.gitignore index 6d47402fa773a15c89cd0bee58dbc37cd58d3017..e9231470cdbd8b91ce7a565094a59545784e6261 100644 --- a/packages/discuz-sdk/.gitignore +++ b/packages/discuz-sdk/.gitignore @@ -7,4 +7,5 @@ typings/ coverage/ package-lock.json dist/ -lib/ \ No newline at end of file +lib/ +dist-mini/ \ No newline at end of file diff --git a/packages/discuz-sdk/gulpfile.js b/packages/discuz-sdk/gulpfile.js index 4042cbbdd4f96e652cf76c0742ebe68f8ee43302..6f1af129212395bc0576f51d13549804347c0168 100644 --- a/packages/discuz-sdk/gulpfile.js +++ b/packages/discuz-sdk/gulpfile.js @@ -17,10 +17,52 @@ gulp.task('clean', () => gulp .src('./dist', { allowEmpty: true }) .pipe(clean())); +const babelWebOptions = { + presets: [ + [ + '@babel/env', + { + targets: { browsers: ['> 1%', 'last 2 versions', 'not ie <= 9'] }, + useBuiltIns: 'usage', + corejs: 3, + }, + ], + ], + plugins: [ + '@babel/plugin-proposal-class-properties', + '@babel/plugin-proposal-object-rest-spread', + '@babel/plugin-transform-arrow-functions', + '@babel/plugin-transform-runtime', + ], +}; + +const babelMiniOptions = { + presets: [ + [ + '@babel/env', + { + targets: { browsers: ['> 1%', 'last 2 versions', 'not ie <= 9'] }, + useBuiltIns: false, + }, + ], + ], + plugins: [ + '@babel/plugin-proposal-class-properties', + '@babel/plugin-proposal-object-rest-spread', + '@babel/plugin-transform-arrow-functions', + '@babel/plugin-transform-runtime', + ], +}; + // babel 构建 gulp.task('build', () => gulp .src('./src/**/*.js') - .pipe(babel()) + .pipe(babel(babelWebOptions)) .pipe(gulp.dest('./dist'))); +gulp.task('build:mini', () => gulp + .src('./src/**/*.js') + .pipe(babel(babelMiniOptions)) + .pipe(gulp.dest('./dist-mini'))); + gulp.task('watch', () => gulp.watch('src/**/*.js', gulp.series('build'))); diff --git a/packages/discuz-sdk/package.json b/packages/discuz-sdk/package.json index 863d4f659743d23190cca3817a771a8c3b88a19b..418eb06fa8fe743a7890fa6395edf5ca73bb65a9 100644 --- a/packages/discuz-sdk/package.json +++ b/packages/discuz-sdk/package.json @@ -16,7 +16,7 @@ "build:web": "DISCUZ_ENV=web npx rollup -c rollup.config.js", "build:mini": "DISCUZ_ENV=mini npx rollup -c rollup.config.js", "build:uniapp": "DISCUZ_ENV=uniapp npx rollup -c rollup.config.js", - "build": "gulp clean && gulp build", + "build": "gulp clean && gulp build && gulp build:mini", "docs": "gulp docs", "watch": "gulp watch", "lint": "eslint -c .eslintrc.js ./ --ext .js,.jsx",