From d511cb48e2ee6870477c7b7abad30a2f304b3dec Mon Sep 17 00:00:00 2001 From: angelzou Date: Mon, 19 Jul 2021 16:42:41 +0800 Subject: [PATCH] feat: sdk babel --- packages/discuz-sdk/.gitignore | 3 ++- packages/discuz-sdk/gulpfile.js | 44 +++++++++++++++++++++++++++++++- packages/discuz-sdk/package.json | 2 +- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/packages/discuz-sdk/.gitignore b/packages/discuz-sdk/.gitignore index 6d47402f..e9231470 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 4042cbbd..6f1af129 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 863d4f65..418eb06f 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", -- Gitee