node.js - Rollup 不捆绑声明文件

标签 node.js typescript build rollupjs

我正在尝试构建一个用 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 构建时,它在我的构建文件夹中创建了这个:

enter image description here

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/

相关文章:

node.js - Typescript 属性 '' 在类型 'never' 上不存在。在 React NodeJs 堆栈中

node.js - 无法使用 pm2 和 ts-node 运行 typescript node.js 应用程序

c++ - 编译没有对应头文件的cpp

ffmpeg - 编译 ffmpeg Ubuntu 16

javascript - 当我尝试提交 HTML 表单时显示错误 “Cannot POST”

node.js - Webpack 没有创建它用来创建的 HTML 文件

java - 将 Amazon RDS 与只读副本结合使用时,如何处理最终的不一致问题?

javascript - 如何循环遍历 Node/Express 中的对象数组并检查 MongoDB 数据库中是否存在匹配项?

typescript - 如何忽略TypeScript中的一行但将其复制到JS?

c# - 使用 C# 创建自定义 NANT 文件