Skip to content

Commit

Permalink
fix(types): 使用 api-extractor 打包类型文件
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Nov 12, 2020
1 parent 55c6046 commit b4c5bbe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,10 @@
"prompts": "2.4.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"rollup": "2.33.1",
"rollup-plugin-dts": "1.4.13",
"shx": "0.3.3",
"standard-version": "9.0.0",
"ts-essentials": "7.0.1",
"type-fest": "0.16.0",
"type-fest": "0.18.0",
"typescript": "4.0.5",
"typescript-snapshots-plugin": "1.7.0",
"vscode-generate-index-standalone": "1.3.0"
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

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

37 changes: 24 additions & 13 deletions scripts/fixTypesBuild.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import fs from 'fs-extra'
import globby from 'globby'
import rollupPluginDts from 'rollup-plugin-dts'
import { Extractor, ExtractorConfig } from '@microsoft/api-extractor'
import { join } from 'path'
import { rollup } from 'rollup'

async function main(rootDir: string) {
const typesDir = join(rootDir, './lib/types')
const typesFile = join(typesDir, './index.d.ts')
const indexFile = join(typesDir, './index.js')
const bundle = await rollup({
input: typesFile,
treeshake: true,
plugins: [rollupPluginDts({ respectExternal: true })],
})
await bundle.generate({
file: typesFile,
format: 'es',

const config = ExtractorConfig.prepare({
configObjectFullPath: join(rootDir, './api-extractor.json'),
configObject: {
projectFolder: rootDir,
mainEntryPointFilePath: typesFile,
bundledPackages: ['type-fest', 'ts-essentials'],
apiReport: { enabled: false, reportFileName: 'report.api.md' },
dtsRollup: { enabled: true, untrimmedFilePath: typesFile },
tsdocMetadata: { enabled: false },
docModel: { enabled: false },
compiler: {
tsconfigFilePath: join(rootDir, './tsconfig.json'),
},
newlineKind: 'lf',
},
packageJsonFullPath: join(rootDir, './package.json'),
packageJson: {
name: 'vtils',
} as any,
})
await bundle.write({
file: typesFile,
format: 'es',
Extractor.invoke(config, {
localBuild: true,
})

const files = await globby(['*', '!index.js', '!index.d.ts'], {
cwd: typesDir,
absolute: true,
Expand Down

0 comments on commit b4c5bbe

Please sign in to comment.