Skip to content

Commit

Permalink
fix: build only-esm lib to cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Apr 4, 2023
1 parent a2a485e commit ffd6020
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
"debug": "^4.3.4",
"esbuild": "^0.17.12",
"fs-extra": "^11.1.1",
"tiny-glob": "^0.2.9"
"on-change": "^4.0.2",
"tiny-glob": "^0.2.9",
"watcher": "^2.2.2"
},
"devDependencies": {
"@minko-fe/eslint-config": "^1.2.31",
Expand All @@ -61,11 +63,9 @@
"conventional-changelog-cli": "^2.2.2",
"eslint": "^8.36.0",
"mock-fs": "^5.2.0",
"on-change": "^4.0.2",
"tsup": "^6.7.0",
"typescript": "^5.0.2",
"vite": "^4.2.1",
"vitest": "^0.29.7",
"watcher": "^2.2.2"
"vitest": "^0.29.7"
}
}
38 changes: 24 additions & 14 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import type { Options } from 'tsup'
import { defineConfig } from 'tsup'

export const tsup = defineConfig((option) => ({
entry: ['src/index.ts'],
dts: true,
clean: false,
format: ['cjs', 'esm'],
minify: false,
platform: 'node',
sourcemap: !!option.watch,
tsconfig: option.watch ? './tsconfig.dev.json' : './tsconfig.json',
esbuildOptions(opts, { format }) {
if (format === 'esm') {
opts.external = ['watcher', 'on-change']
}
const commonConfig = (option: Options): Options => {
return {
clean: false,
minify: false,
platform: 'node',
sourcemap: !!option.watch,
tsconfig: option.watch ? './tsconfig.dev.json' : './tsconfig.json',
}
}

export const tsup = defineConfig((option) => [
{
entry: ['src/index.ts'],
dts: true,
format: ['esm'],
...commonConfig(option),
},
{
entry: ['src/index.ts'],
noExternal: ['on-change', 'watcher'],
format: ['cjs'],
...commonConfig(option),
},
}))
])

0 comments on commit ffd6020

Please sign in to comment.