From 70c31d0bec5319bc623d86525721d6ac8e27c9b1 Mon Sep 17 00:00:00 2001 From: jeremywu <591449570@qq.com> Date: Sun, 27 Dec 2020 18:05:32 +0800 Subject: [PATCH] build(build): buid/add-locale-theme-in-es-build (#1132) - Now lib provides cjs format exports and es provides esm format --- .github/workflows/publish-npm.yml | 10 ------ build/build-util.js | 54 +++++++++++++++++++++++++++++++ packages/utils/popup-manager.ts | 2 +- scripts/build.sh | 9 ++++-- scripts/publish.sh | 2 +- 5 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 build/build-util.js diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index d56c1c7a7c..7f339b8de5 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -43,13 +43,3 @@ jobs: NODE_AUTH_TOKEN: ${{secrets.NPM_PUBLISH_TOKEN}} TAG_VERSION: ${{env.TAG_VERSION}} REGISTRY: https://registry.npmjs.com/ - PKG_NAME: element-plus - - name: Generate grp token - run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ./.npmrc - - name: Publish grp - run: sh ./scripts/publish.sh - env: - NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} - TAG_VERSION: ${{env.TAG_VERSION}} - REGISTRY: https://npm.pkg.github.com/ - PKG_NAME: "@element-plus/element-plus" diff --git a/build/build-util.js b/build/build-util.js new file mode 100644 index 0000000000..70ae6688be --- /dev/null +++ b/build/build-util.js @@ -0,0 +1,54 @@ +/* eslint-disable */ +const pkg = require('../package.json') +const path = require('path') +const { nodeResolve } = require('@rollup/plugin-node-resolve') +const rollup = require('rollup') +const typescript = require('rollup-plugin-typescript2') + +const deps = Object.keys(pkg.dependencies) + +const root = path.resolve(__dirname, '..'); +const file = process.argv[2]; +const defaultOpts = { + input: path.resolve(root, file), + plugins: [ + nodeResolve(), + typescript({ + tsconfigOverride: { + compilerOptions: { + declaration: false, + }, + 'exclude': [ + 'node_modules', + '__tests__', + ], + }, + abortOnError: false, + }), + ], + external(id) { + return /^vue/.test(id) + || /^@vue/.test(id) + || deps.some(k => new RegExp('^' + k).test(id)) + }, +} + +const run = async (name) => { + const esm = { + format: 'es', + file: `es/${name}`, + }; + const cjs = { + format: 'cjs', + file: `lib/${name}`, + exports: 'named', + } + + const bundle = await rollup.rollup(defaultOpts); + await Promise.all([bundle.write(esm), bundle.write(cjs)]); + console.log(name, 'build finished'); +} + +let normalizedName = file.slice(11); // remove ./packages + +run(`${normalizedName.split('.').shift()}.js`); diff --git a/packages/utils/popup-manager.ts b/packages/utils/popup-manager.ts index 3cb4e0566f..d46f12a23a 100644 --- a/packages/utils/popup-manager.ts +++ b/packages/utils/popup-manager.ts @@ -1,9 +1,9 @@ -import { Ref } from 'vue' import isServer from './isServer' import { getConfig } from './config' import { addClass, removeClass, on } from './dom' import { EVENT_CODE } from './aria' +import type { Ref } from 'vue' interface Instance { closeOnClickModal: Ref closeOnPressEscape: Ref diff --git a/scripts/build.sh b/scripts/build.sh index 2e159ca805..5b20cf5338 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -20,11 +20,14 @@ yarn build:lib-full # node .build/build.js command find './packages' -type d -maxdepth 1 ! -name '*util*' ! -name '__mocks__' ! -name 'locale' ! -name 'theme*' -print0 | xargs -I {} -P6 -0 node ./build/build.comps.js {} + +find ./packages/utils -type f ! -name '*.test.ts' ! -name 'package.json' -print0 \ +| xargs -P6 -0 -I {} node ./build/build-util.js {} + node ./build/build.entry.js -yarn build:utils - -yarn build:locale +find ./packages/locale -type f ! -name '*.spec.ts' ! -name 'package.json' -print0 \ +| xargs -P6 -0 -I {} node ./build/build-util.js {} yarn build:locale-umd diff --git a/scripts/publish.sh b/scripts/publish.sh index bf7d3588c0..15f93f3c98 100644 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -7,7 +7,7 @@ cat package.json \ | grep -v '"private":' \ | grep -v '"version":' \ -| sed "s/\(\"name\": \"element-plus\"\)/\"name\": \"${PKG_NAME}\",\n \"version\": \"${TAG_VERSION}\"/g" > package.json.bak +| sed "s/\(\"name\": \"element-plus\"\)/\1,\n \"version\": \"${TAG_VERSION}\"/g" > package.json.bak cat package.json.bak > package.json npm publish --registry ${REGISTRY}