Skip to content

Commit c507e70

Browse files
committed
fix(taro-platform-h5): 生成definition.json api为空
1 parent 5e4de56 commit c507e70

File tree

4 files changed

+202
-187
lines changed

4 files changed

+202
-187
lines changed

packages/taro-h5/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
"rollup": "^3.29.4",
7272
"rollup-plugin-node-externals": "^5.0.0",
7373
"@rollup/plugin-typescript": "^12.1.2",
74-
"@rollup/plugin-node-resolve": "^15.2.3"
74+
"@rollup/plugin-node-resolve": "^15.2.3",
75+
"rollup-plugin-dts": "^6.2.1"
7576
},
7677
"peerDependencies": {
7778
"@tarojs/components": "workspace:~"

packages/taro-h5/rollup.config.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve'
33
import ts from '@rollup/plugin-typescript'
44
import { mergeWith } from 'lodash'
55
import { defineConfig } from 'rollup'
6+
import { dts } from 'rollup-plugin-dts'
67
import externals from 'rollup-plugin-node-externals'
78
import postcss from 'rollup-plugin-postcss'
89

@@ -46,6 +47,20 @@ const variesConfig: RollupOptions[] = [
4647
},
4748
]
4849

50+
variesConfig.push({
51+
input: 'src/index.ts',
52+
output: {
53+
file: 'dist/index.esm.js',
54+
inlineDynamicImports: true
55+
}
56+
},
57+
{
58+
// 需要该配置才能生成打包的 .d.ts 文件供 taro-platform-h5\build\definition-json\parser.ts 生成 apis 配置
59+
input: 'src/index.ts',
60+
output: { file: 'dist/index.esm.d.ts' },
61+
plugins: [dts()]
62+
})
63+
4964
if (process.env.NODE_ENV === 'production') {
5065
variesConfig.push(
5166
{
@@ -55,25 +70,10 @@ if (process.env.NODE_ENV === 'production') {
5570
file: 'dist/index.cjs.js',
5671
inlineDynamicImports: true,
5772
},
58-
},
59-
{
60-
input: 'src/index.ts',
61-
output: {
62-
file: 'dist/index.esm.js',
63-
inlineDynamicImports: true,
64-
},
6573
}
6674
)
6775
}
6876

69-
variesConfig.push({
70-
input: 'src/index.ts',
71-
output: {
72-
file: 'dist/index.esm.js',
73-
inlineDynamicImports: true
74-
}
75-
})
76-
7777
export default defineConfig(
7878
variesConfig.map((v) => {
7979
const customizer = function (objValue, srcValue) {

packages/taro-platform-h5/build/definition-json/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function parseAnyOrVoid (str = '', obj: unknown = str) {
9494
}
9595

9696
export function parseDefinitionJSON ({
97-
apisPath = require.resolve('@tarojs/taro-h5/dist/index.d.ts'),
97+
apisPath = require.resolve('@tarojs/taro-h5/dist/index.esm.d.ts'),
9898
componentsPath = require.resolve('@tarojs/components/dist/types/components.d.ts'),
9999
} = {},
100100
config: ts.CompilerOptions = tsconfig,

0 commit comments

Comments
 (0)