这是indexloc提供的服务,不要输入任何密码
Skip to content

How to generate .d.ts.map #564

@eric-burel

Description

@eric-burel

Hi,

I am able to generate .d.ts, however in a monorepo it's also a requirement to produce .d.ts.map files to allow jumping between files (see https://stackoverflow.com/questions/55318663/how-to-generate-d-ts-and-d-ts-map-files-using-webpack).

My tsconfig enables declarationMap, however it doesn't seem to be respected by tsup. Do you have an idea of how to force this parameter to be taken into account? I guess you use tsc under the hood so that's just a matter of passing the right config.

My tsup.config.ts:

import { defineConfig } from "tsup";

const commonConfig = {
  clean: true,
  splitting: false,
  dts: true,
  sourcemap: true,
};
export default defineConfig([
  {
    entry: ["index.ts"],
    ...commonConfig,
    format: ["cjs", "esm", "iife"],
    outDir: "dist",
  },

Adding: tsconfig: path.resolve(__dirname, "./tsconfig.build.json"), (with the config enabling declarationMap) doesn't seem to work.

My tsconfig.json:

{
  "compilerOptions": {
    "allowJs": false,
    "alwaysStrict": true,
    "declaration": true,
    "declarationMap": true, // Allow navigation to definition in VS Code https://stackoverflow.com/questions/54459847/vscode-lerna-typescript-monorepo-code-navigation
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "react",
    "lib": [
      "es6",
      "dom"
    ],
    "module": "commonjs",
    "moduleResolution": "node",
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": false,
    "noLib": false,
    "noUnusedLocals": false, // won't fail on unused variables
    "noUnusedParameters": false,
    "removeComments": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strictNullChecks": true,
    "strictBindCallApply": true, // @see https://github.com/storybookjs/storybook/issues/11916
    "sourceMap": true,
    "strict": false,
    "target": "es6",
    "typeRoots": [
      "./types",
      "./node_modules/@types"
    ]
  },
  "exclude": [
    "node_modules",
    "**/*.d.ts",
    "**/dist/*",
    "**/webpack.config.js",
    // @see https://github.com/facebook/docusaurus/issues/3424
    "packages/docusaurus"
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions