【发布时间】:2021-10-25 13:45:35
【问题描述】:
这似乎是一个非常微不足道的问题。我有一个使用 rollup-plugin-typescript 和 rollup-plugin-dts 的汇总打字稿配置。我想将我所有的 d.ts 文件捆绑到一个 d.ts 文件中,而不是让它镜像我的项目结构。我遵循了一些教程并最终获得了以下配置。
问题:dts() 正确地捆绑了文件,但保留了原来的构建结构。我的资源都没有解决这个问题。不应该删除现在过时的输入文件吗?我处理插件不好?
我从哪里开始:
dist/
├── index.js
├─ dts //I compile my types into here, below is my mirrored project structure
├── components
│ ├── Button.d.ts
│ ├── index.d.ts
├── index.d.ts
我想要什么:
dist/
├── index.js
├── index.d.ts //everything bundled here
不幸的是我得到了什么:
dist/
├── index.js
├─ dts //All of this is still here, it shouldn't be
├── components
│ ├── Button.d.ts
│ ├── index.d.ts
├── index.d.ts
├── index.d.ts //It bundled correctly to this additional file though
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationDir": "dts",
"downlevelIteration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es5",
"strictFunctionTypes": true
},
"include": ["src/"],
"exclude": ["node_modules", "build", "dist", "src/stories/**", "**/*.stories.ts", "**/*.test.ts", "**/*.test.tsx"]
}
rollup.config.js
import babel from 'rollup-plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import external from 'rollup-plugin-peer-deps-external';
import { terser } from 'rollup-plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import dts from 'rollup-plugin-dts';
import typescript from '@rollup/plugin-typescript';
export default [
{
input: './src/index.ts',
output: [
{
file: 'dist/index.js',
format: 'cjs',
},
{
file: 'dist/index.es.js',
format: 'es',
exports: 'named',
},
],
plugins: [
typescript({
tsconfig: './tsconfig.json',
}),
babel({
exclude: 'node_modules/**',
presets: ['@babel/preset-react'],
}),
resolve(),
commonjs(),
external(),
terser(),
],
},
{
input: './dist/dts/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: 'es' }],
plugins: [dts()],
},
];
【问题讨论】:
标签: typescript rollup .d.ts