Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
chore: refactor build
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed May 7, 2024
1 parent bfcea45 commit 3d9b10e
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 82 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@types/validate-npm-package-name": "^4.0.2",
"bundle-require": "^4.0.2",
"chokidar": "^3.6.0",
"conventional-changelog-cli": "^2.2.2",
"esbuild": "^0.17.19",
"eslint": "^8.56.0",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
Expand All @@ -57,6 +54,8 @@
"strip-dirs": "^3.0.0",
"taze": "^0.13.3",
"tsup": "^8.0.2",
"tsup-plugin-bundleless": "^0.1.2",
"tsup-plugin-css-legacy": "^0.0.1",
"tsx": "^4.7.0",
"turbo": "^1.12.3",
"typescript": "^5.3.3",
Expand Down
12 changes: 4 additions & 8 deletions packages/lodash-pro/scripts/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fileSuffixPlugin } from '~scripts/utils'
import { type Options } from 'tsup'
import { bundleless } from 'tsup-plugin-bundleless'

const tsupConfig: Options = {
entry: ['src/**/*.ts'],
Expand All @@ -13,7 +13,7 @@ export const esm: Options = {
target: 'es2020',
outDir: 'dist/es',
outExtension: () => ({ js: '.js' }),
esbuildPlugins: [fileSuffixPlugin('esm')],
plugins: [bundleless({ ext: '.js' })],
}

export const cjs: Options = {
Expand All @@ -22,11 +22,7 @@ export const cjs: Options = {
outDir: 'dist/lib',
target: 'es2020',
platform: 'node',
outExtension: () => ({ js: '.cjs' }),
noExternal: ['lodash-es', 'p-is-promise'],
esbuildPlugins: [
fileSuffixPlugin('cjs', {
noExternal: ['lodash-es', 'p-is-promise'],
}),
],
outExtension: () => ({ js: '.cjs' }),
plugins: [bundleless({ ext: '.cjs' })],
}
8 changes: 4 additions & 4 deletions packages/react-component/scripts/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fileSuffixPlugin, getEntry } from '~scripts/utils'
import { getEntry } from '~scripts/utils'
import { type Options } from 'tsup'
import { bundleless } from 'tsup-plugin-bundleless'

const tsupConfig: Options = {
// tree-shaking
Expand All @@ -8,21 +9,20 @@ const tsupConfig: Options = {
entry: getEntry('src/**/*.{ts,tsx}'),
},
platform: 'browser',
minify: 'terser',
}

export const esm: Options = {
...tsupConfig,
format: ['esm'],
outDir: 'dist/es',
outExtension: () => ({ js: '.js' }),
esbuildPlugins: [fileSuffixPlugin('esm')],
plugins: [bundleless({ ext: '.js' })],
}

export const cjs: Options = {
...tsupConfig,
format: ['cjs'],
outDir: 'dist/lib',
outExtension: () => ({ js: '.cjs' }),
esbuildPlugins: [fileSuffixPlugin('cjs')],
plugins: [bundleless({ ext: '.cjs' })],
}
6 changes: 3 additions & 3 deletions packages/react-hook/scripts/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fileSuffixPlugin } from '~scripts/utils'
import { type Options } from 'tsup'
import { bundleless } from 'tsup-plugin-bundleless'

const tsupConfig: Options = {
entry: ['src/**/*.ts'],
Expand All @@ -14,13 +14,13 @@ export const esm: Options = {
format: ['esm'],
outDir: 'dist/es',
outExtension: () => ({ js: '.js' }),
esbuildPlugins: [fileSuffixPlugin('esm')],
plugins: [bundleless({ ext: '.js' })],
}

export const cjs: Options = {
...tsupConfig,
format: ['cjs'],
outDir: 'dist/lib',
outExtension: () => ({ js: '.cjs' }),
esbuildPlugins: [fileSuffixPlugin('cjs')],
plugins: [bundleless({ ext: '.cjs' })],
}
2 changes: 1 addition & 1 deletion packages/react-locale/scripts/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export default {
'client/index': 'src/client/index.ts',
'node/plugin/index': 'src/node/plugin/index.ts',
},
target: 'es6',
target: 'es2015',
format: ['cjs', 'esm'],
} as Options
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { isObject, isUndefined } from '@minko-fe/lodash-pro'
import { getTsconfig } from 'get-tsconfig'
import { type Options, build as tsupBuild } from 'tsup'
import { cssLegacy } from 'tsup-plugin-css-legacy'
import { defaultConfig } from './utils/config'

async function build(options: Options = {}, watchMode = false) {
let { dts, esbuildOptions, external, ...rest } = options
let { dts, esbuildOptions, external, plugins, ...rest } = options

const tsconfig = getTsconfig()

Expand All @@ -29,12 +30,13 @@ async function build(options: Options = {}, watchMode = false) {
opt.logOverride = {
'empty-import-meta': 'silent',
}

esbuildOptions?.(opt, { format })
},
external: [...(defaultConfig.external || []), ...(external || [])],
dts,
clean: true,
minify: true,
plugins: [...(plugins || []), cssLegacy()],
...rest,
})
}
Expand Down
3 changes: 1 addition & 2 deletions scripts/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export const defaultConfig: Options = {
splitting: false,
watch: false,
treeshake: true,
target: 'es6',
keepNames: true,
target: 'es2015',
shims: false,
clean: false,
config: false,
Expand Down
56 changes: 0 additions & 56 deletions scripts/utils/esbuild/file-suffix-plugin.ts

This file was deleted.

3 changes: 0 additions & 3 deletions scripts/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import glob from 'fast-glob'
import path from 'node:path'
import stripDirs from 'strip-dirs'
import { fileSuffixPlugin } from './esbuild/file-suffix-plugin'

// Taken from https://github.com/sindresorhus/slash/blob/main/index.js (MIT)
export function slash(path: string) {
Expand Down Expand Up @@ -58,5 +57,3 @@ export function getEntry(entryGlob = 'src/index.ts{,x}') {

return entry
}

export { fileSuffixPlugin }

0 comments on commit 3d9b10e

Please sign in to comment.