我正在尝试构建一个用 TypeScript 制作的库。我正在使用 paths
房产在tsconfig.json
.
我的 tsconfig.json
看起来像这样:
{
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"target": "es2015",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"experimentalDecorators": true,
"sourceMap": true,
"lib": [
"esnext",
"dom"
],
"strict": true,
"sourceRoot": "./src",
"rootDir": "./src",
"outDir": "build",
"declaration": true,
"declarationDir": "build",
"baseUrl": "./src",
"noUnusedLocals": true,
"paths": {
"modules/*": [
"modules/*"
],
"common/*": [
"common/*"
]
}
},
"exclude": [
"node_modules",
"build"
]
}
我的汇总配置如下所示:
import typescript from 'rollup-plugin-typescript2'
export default {
entry: "./src/index.ts",
output: {
file: './build/index.js',
format: 'cjs'
},
plugins: [
typescript({ typescript: require("typescript"), declaration: true, clean: true })
]
}
但是,当我使用
rollup -c
构建时,它在我的构建文件夹中创建了这个:index.js 捆绑得很好,但这里的声明文件只是从
/common
导入文件夹,该文件夹基本上包含来自 src
的所有其他文件夹。目录但每个文件夹只有一个声明文件,此外,这些文件尝试使用 paths
导入别名而不是使用相对导入构建,因此它们不起作用。我如何告诉 rollup 构建单个声明文件而不是这个?
最佳答案
rollup-plugin-typescript
保留声明文件的文件夹结构。要捆绑声明,您应该使用 rollup-plugin-ts
还有:
https://github.com/wessberg/rollup-plugin-ts
关于node.js - Rollup 不捆绑声明文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51721177/