From 74bc0879c4e12ef5ae6d727413dbade64ea69ac3 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Thu, 11 Nov 2021 11:08:02 +0800 Subject: [PATCH] build: using rollup-plugin-esbuild --- packages/vant-popperjs/babel.config.js | 3 - packages/vant-popperjs/package.json | 15 ++-- packages/vant-popperjs/rollup.config.js | 7 +- packages/vant-popperjs/tsconfig.json | 6 +- packages/vant-use/README.md | 4 - packages/vant-use/babel.config.js | 3 - packages/vant-use/package.json | 13 ++-- packages/vant-use/rollup.config.js | 18 +++++ packages/vant-use/scripts/build.js | 40 ---------- .../vant-use/{src => }/test/utils.spec.ts | 2 +- packages/vant-use/tsconfig.json | 7 +- pnpm-lock.yaml | 74 ++++++++++--------- 12 files changed, 80 insertions(+), 112 deletions(-) delete mode 100644 packages/vant-popperjs/babel.config.js delete mode 100644 packages/vant-use/babel.config.js create mode 100644 packages/vant-use/rollup.config.js delete mode 100644 packages/vant-use/scripts/build.js rename packages/vant-use/{src => }/test/utils.spec.ts (72%) diff --git a/packages/vant-popperjs/babel.config.js b/packages/vant-popperjs/babel.config.js deleted file mode 100644 index 3022f59d1..000000000 --- a/packages/vant-popperjs/babel.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - presets: [['@vant/cli/preset.cjs', { loose: true }]], -}; diff --git a/packages/vant-popperjs/package.json b/packages/vant-popperjs/package.json index c34ddd675..ebd14d8cb 100644 --- a/packages/vant-popperjs/package.json +++ b/packages/vant-popperjs/package.json @@ -14,8 +14,11 @@ "registry": "https://registry.npmjs.org/" }, "scripts": { + "clean": "rm -rf ./dist", "dev": "rollup --config rollup.config.js --watch", - "build": "rollup --config rollup.config.js && tsc -p ./tsconfig.json --emitDeclarationOnly", + "build:types": "tsc -p ./tsconfig.json --emitDeclarationOnly", + "build:bundle": "rollup --config rollup.config.js", + "build": "pnpm clean && pnpm build:bundle && pnpm build:types", "release": "pnpm build && release-it", "prepare": "pnpm build" }, @@ -25,11 +28,11 @@ "@popperjs/core": "^2.9.2" }, "devDependencies": { - "@vant/cli": "workspace:*", - "@rollup/plugin-babel": "^5.2.1", - "@rollup/plugin-node-resolve": "^10.0.0", - "release-it": "^14.2.2", - "rollup": "^2.33.3" + "typescript": "4.x", + "rollup": "^2.33.3", + "rollup-plugin-esbuild": "^4.6.0", + "@rollup/plugin-node-resolve": "^13.0.0", + "release-it": "^14.2.2" }, "release-it": { "git": { diff --git a/packages/vant-popperjs/rollup.config.js b/packages/vant-popperjs/rollup.config.js index c06f520e8..7a76e73a7 100644 --- a/packages/vant-popperjs/rollup.config.js +++ b/packages/vant-popperjs/rollup.config.js @@ -1,5 +1,5 @@ import path from 'path'; -import babel from '@rollup/plugin-babel'; +import esbuild from 'rollup-plugin-esbuild'; import nodeResolve from '@rollup/plugin-node-resolve'; export default { @@ -14,8 +14,5 @@ export default { format: 'esm', }, ], - plugins: [ - babel({ babelHelpers: 'bundled', extensions: ['.js', '.ts'] }), - nodeResolve(), - ], + plugins: [esbuild(), nodeResolve()], }; diff --git a/packages/vant-popperjs/tsconfig.json b/packages/vant-popperjs/tsconfig.json index f7f1373d7..ac6b07b09 100644 --- a/packages/vant-popperjs/tsconfig.json +++ b/packages/vant-popperjs/tsconfig.json @@ -2,13 +2,11 @@ "compilerOptions": { "target": "ES2015", "outDir": "./dist", - "module": "ES2015", + "module": "ESNext", "strict": true, "declaration": true, "skipLibCheck": true, - "esModuleInterop": true, - "moduleResolution": "node", - "lib": ["esnext", "dom"] + "moduleResolution": "Node", }, "include": ["src/**/*"] } diff --git a/packages/vant-use/README.md b/packages/vant-use/README.md index ff6b33ac0..280419866 100644 --- a/packages/vant-use/README.md +++ b/packages/vant-use/README.md @@ -4,10 +4,6 @@ Vant Use 是从 Vant 实际应用场景中沉淀的 Vue 组合式 API 库。 ## 安装 -如果项目中已经安装了 Vant 3,则无须手动安装 Vant Use。 - -如果项目中未使用 Vant,可以通过 `npm` 或 `yarn` 手动安装 Vant Use。 - ```bash # 通过 npm 安装 npm i @vant/use -S diff --git a/packages/vant-use/babel.config.js b/packages/vant-use/babel.config.js deleted file mode 100644 index 3022f59d1..000000000 --- a/packages/vant-use/babel.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - presets: [['@vant/cli/preset.cjs', { loose: true }]], -}; diff --git a/packages/vant-use/package.json b/packages/vant-use/package.json index 308bd14ab..b3770740d 100644 --- a/packages/vant-use/package.json +++ b/packages/vant-use/package.json @@ -4,16 +4,17 @@ "description": "Vant Composition API", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", - "typings": "dist/types/index.d.ts", + "typings": "dist/index.d.ts", "sideEffects": false, "files": [ "dist" ], "scripts": { "clean": "rm -rf ./dist", - "build:lib": "node ./scripts/build.js", + "dev": "rollup --config rollup.config.js --watch", "build:types": "tsc -p ./tsconfig.json --emitDeclarationOnly", - "build": "pnpm build:lib && pnpm build:types", + "build:bundle": "rollup --config rollup.config.js", + "build": "pnpm clean && pnpm build:bundle && pnpm build:types", "release": "pnpm build && release-it", "prepare": "pnpm build" }, @@ -24,12 +25,10 @@ "license": "MIT", "repository": "https://github.com/youzan/vant/tree/dev/packages/vant-use", "devDependencies": { - "@babel/core": "^7.12.9", - "@vant/cli": "workspace:*", - "fast-glob": "^3.2.7", - "fs-extra": "^10.0.0", "release-it": "^14.0.2", "typescript": "4.x", + "rollup": "^2.33.3", + "rollup-plugin-esbuild": "^4.6.0", "vue": "^3.2.20" }, "release-it": { diff --git a/packages/vant-use/rollup.config.js b/packages/vant-use/rollup.config.js new file mode 100644 index 000000000..4a3a5096b --- /dev/null +++ b/packages/vant-use/rollup.config.js @@ -0,0 +1,18 @@ +import path from 'path'; +import esbuild from 'rollup-plugin-esbuild'; + +export default { + input: path.join(__dirname, 'src', 'index.ts'), + output: [ + { + dir: 'dist/cjs', + format: 'cjs', + }, + { + dir: 'dist/esm', + format: 'esm', + }, + ], + external: ['vue'], + plugins: [esbuild()], +}; diff --git a/packages/vant-use/scripts/build.js b/packages/vant-use/scripts/build.js deleted file mode 100644 index e1c0fa036..000000000 --- a/packages/vant-use/scripts/build.js +++ /dev/null @@ -1,40 +0,0 @@ -const glob = require('fast-glob'); -const { join } = require('path'); -const { transformAsync } = require('@babel/core'); -const { readFileSync, outputFileSync } = require('fs-extra'); - -const srcDir = join(__dirname, '..', 'src'); -const distDir = join(__dirname, '..', 'dist'); -const srcFiles = glob.sync(join(srcDir, '**', '*.ts'), { - ignore: ['**/node_modules', '**/*.spec.ts'], -}); - -const compile = (filePath, distDir) => - new Promise((resolve, reject) => { - const code = readFileSync(filePath, 'utf-8'); - const distPath = filePath.replace(srcDir, distDir).replace('.ts', '.js'); - - transformAsync(code, { filename: filePath }) - .then((result) => { - if (result) { - outputFileSync(distPath, result.code); - resolve(); - } - }) - .catch(reject); - }); - -async function build() { - // esm output - await Promise.all( - srcFiles.map((srcFile) => compile(srcFile, join(distDir, 'esm'))) - ); - - // cjs output - process.env.BABEL_MODULE = 'commonjs'; - await Promise.all( - srcFiles.map((srcFile) => compile(srcFile, join(distDir, 'cjs'))) - ); -} - -build(); diff --git a/packages/vant-use/src/test/utils.spec.ts b/packages/vant-use/test/utils.spec.ts similarity index 72% rename from packages/vant-use/src/test/utils.spec.ts rename to packages/vant-use/test/utils.spec.ts index 68b3e7c32..9c1b9b085 100644 --- a/packages/vant-use/src/test/utils.spec.ts +++ b/packages/vant-use/test/utils.spec.ts @@ -1,4 +1,4 @@ -import { raf, cancelRaf } from '../utils'; +import { raf, cancelRaf } from '../src/utils'; test('raf', async () => { const spy = jest.fn(); diff --git a/packages/vant-use/tsconfig.json b/packages/vant-use/tsconfig.json index 0137ed67d..ac6b07b09 100644 --- a/packages/vant-use/tsconfig.json +++ b/packages/vant-use/tsconfig.json @@ -1,13 +1,12 @@ { "compilerOptions": { "target": "ES2015", - "outDir": "./dist/types", - "module": "ES2015", + "outDir": "./dist", + "module": "ESNext", "strict": true, "declaration": true, "skipLibCheck": true, - "esModuleInterop": true, - "moduleResolution": "Node" + "moduleResolution": "Node", }, "include": ["src/**/*"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a04714724..d09c09e9c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -247,19 +247,19 @@ importers: packages/vant-popperjs: specifiers: '@popperjs/core': ^2.9.2 - '@rollup/plugin-babel': ^5.2.1 - '@rollup/plugin-node-resolve': ^10.0.0 - '@vant/cli': workspace:* + '@rollup/plugin-node-resolve': ^13.0.0 release-it: ^14.2.2 rollup: ^2.33.3 + rollup-plugin-esbuild: ^4.6.0 + typescript: 4.x dependencies: '@popperjs/core': 2.10.2 devDependencies: - '@rollup/plugin-babel': 5.3.0_rollup@2.59.0 - '@rollup/plugin-node-resolve': 10.0.0_rollup@2.59.0 - '@vant/cli': link:../vant-cli + '@rollup/plugin-node-resolve': 13.0.6_rollup@2.59.0 release-it: 14.11.6 rollup: 2.59.0 + rollup-plugin-esbuild: 4.6.0_rollup@2.59.0 + typescript: 4.4.4 packages/vant-stylelint-config: specifiers: @@ -277,19 +277,15 @@ importers: packages/vant-use: specifiers: - '@babel/core': ^7.12.9 - '@vant/cli': workspace:* - fast-glob: ^3.2.7 - fs-extra: ^10.0.0 release-it: ^14.0.2 + rollup: ^2.33.3 + rollup-plugin-esbuild: ^4.6.0 typescript: 4.x vue: ^3.2.20 devDependencies: - '@babel/core': 7.16.0 - '@vant/cli': link:../vant-cli - fast-glob: 3.2.7 - fs-extra: 10.0.0 release-it: 14.11.6 + rollup: 2.59.0 + rollup-plugin-esbuild: 4.6.0_rollup@2.59.0 typescript: 4.4.4 vue: 3.2.21 @@ -1949,27 +1945,11 @@ packages: resolution: {integrity: sha1-B5jAM1Hw3qGlpMq93yalWny+5ZA=, tarball: '@popperjs/core/download/@popperjs/core-2.10.2.tgz'} dev: false - /@rollup/plugin-babel/5.3.0_rollup@2.59.0: - resolution: {integrity: sha1-nLHFFG3daklorZbyCcUMYvkvmHk=, tarball: '@rollup/plugin-babel/download/@rollup/plugin-babel-5.3.0.tgz'} + /@rollup/plugin-node-resolve/13.0.6_rollup@2.59.0: + resolution: {integrity: sha1-KWKQcLt2dWe+gVf1dc+o8rjp73c=, tarball: '@rollup/plugin-node-resolve/download/@rollup/plugin-node-resolve-13.0.6.tgz'} engines: {node: '>= 10.0.0'} peerDependencies: - '@babel/core': ^7.0.0 - '@types/babel__core': ^7.1.9 - rollup: ^1.20.0||^2.0.0 - peerDependenciesMeta: - '@types/babel__core': - optional: true - dependencies: - '@babel/helper-module-imports': 7.16.0 - '@rollup/pluginutils': 3.1.0_rollup@2.59.0 - rollup: 2.59.0 - dev: true - - /@rollup/plugin-node-resolve/10.0.0_rollup@2.59.0: - resolution: {integrity: sha1-RAZKK5jfdTDmas+JQf8mL8m06tg=, tarball: '@rollup/plugin-node-resolve/download/@rollup/plugin-node-resolve-10.0.0.tgz'} - engines: {node: '>= 10.0.0'} - peerDependencies: - rollup: ^1.20.0||^2.0.0 + rollup: ^2.42.0 dependencies: '@rollup/pluginutils': 3.1.0_rollup@2.59.0 '@types/resolve': 1.17.1 @@ -1998,7 +1978,6 @@ packages: dependencies: estree-walker: 2.0.2 picomatch: 2.3.0 - dev: false /@sindresorhus/is/0.14.0: resolution: {integrity: sha1-n7OjzzEyMoFR81PeRjLgHlIQK+o=, tarball: '@sindresorhus/is/download/@sindresorhus/is-0.14.0.tgz'} @@ -3571,7 +3550,7 @@ packages: resolution: {integrity: sha1-pvLc5hL63S7x9Rm3NVHxfoUZmDE=, tarball: deep-is/download/deep-is-0.1.4.tgz} /deepmerge/4.2.2: - resolution: {integrity: sha1-RNLqNnm49NT/ujPwPYZfwee/SVU=, tarball: deepmerge/download/deepmerge-4.2.2.tgz?cache=0&sync_timestamp=1632822781299&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fdeepmerge%2Fdownload%2Fdeepmerge-4.2.2.tgz} + resolution: {integrity: sha1-RNLqNnm49NT/ujPwPYZfwee/SVU=, tarball: deepmerge/download/deepmerge-4.2.2.tgz} engines: {node: '>=0.10.0'} /defaults/1.0.3: @@ -4432,6 +4411,7 @@ packages: graceful-fs: 4.2.8 jsonfile: 6.1.0 universalify: 2.0.0 + dev: false /fs-extra/8.1.0: resolution: {integrity: sha1-SdQ8RaiM2Wd2aMt74bRu/bjS4cA=, tarball: fs-extra/download/fs-extra-8.1.0.tgz?cache=0&sync_timestamp=1632822706452&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Ffs-extra%2Fdownload%2Ffs-extra-8.1.0.tgz} @@ -5789,6 +5769,11 @@ packages: - utf-8-validate dev: false + /joycon/3.0.1: + resolution: {integrity: sha1-kHTJsIzPN6Zyb/dKGEhfhe/K3a8=, tarball: joycon/download/joycon-3.0.1.tgz} + engines: {node: '>=10'} + dev: true + /js-tokens/4.0.0: resolution: {integrity: sha1-GSA/tZmR35jjoocFDUZHzerzJJk=, tarball: js-tokens/download/js-tokens-4.0.0.tgz} @@ -5898,6 +5883,10 @@ packages: dependencies: minimist: 1.2.5 + /jsonc-parser/3.0.0: + resolution: {integrity: sha1-q914VwHH5+rKip7IzwcMpRp0WiI=, tarball: jsonc-parser/download/jsonc-parser-3.0.0.tgz} + dev: true + /jsonfile/4.0.0: resolution: {integrity: sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=, tarball: jsonfile/download/jsonfile-4.0.0.tgz} optionalDependencies: @@ -5910,6 +5899,7 @@ packages: universalify: 2.0.0 optionalDependencies: graceful-fs: 4.2.8 + dev: false /jsonparse/1.3.1: resolution: {integrity: sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=, tarball: jsonparse/download/jsonparse-1.3.1.tgz} @@ -7315,6 +7305,19 @@ packages: dependencies: glob: 7.2.0 + /rollup-plugin-esbuild/4.6.0_rollup@2.59.0: + resolution: {integrity: sha1-KTsMjS5kt1ORjzAjwfuH3ErN7zs=, tarball: rollup-plugin-esbuild/download/rollup-plugin-esbuild-4.6.0.tgz} + engines: {node: '>=12'} + peerDependencies: + esbuild: '>=0.10.1' + rollup: ^1.20.0 || ^2.0.0 + dependencies: + '@rollup/pluginutils': 4.1.1 + joycon: 3.0.1 + jsonc-parser: 3.0.0 + rollup: 2.59.0 + dev: true + /rollup/2.59.0: resolution: {integrity: sha1-EIxhsPoKN+vI0fFk8oFiIFbw21k=, tarball: rollup/download/rollup-2.59.0.tgz} engines: {node: '>=10.0.0'} @@ -8115,6 +8118,7 @@ packages: /universalify/2.0.0: resolution: {integrity: sha1-daSYTv7cSwiXXFrrc/Uw0C3yVxc=, tarball: universalify/download/universalify-2.0.0.tgz} engines: {node: '>= 10.0.0'} + dev: false /update-notifier/5.1.0: resolution: {integrity: sha1-SrDXx/NqIx3XMWz3cpMT8CFNmtk=, tarball: update-notifier/download/update-notifier-5.1.0.tgz}