0

我在雪包中有以下配置:

/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
  mount: {
        public:{ url: '/', static: true },
        src: { url: '/dist' },
        runtime: { url: '/runtime' },
  },
  plugins: [
        '@snowpack/plugin-typescript',
        ['@snowpack/plugin-babel', 
            {
                'input': ['.ts', '.tsx'],
            }
        ]
  ],
  packageOptions: {
    /* ... */
  },
  devOptions: {
    /* ... */
  },
  buildOptions: {
    /* ... */
  },
};

这是在我的声明文件中index.d.ts,但是当我启动开发服务器时,Snowpack 没有读取它。

declare global {
    namespace JSX {
        interface IntrinsicElements {
            [elName: string]: any;
        }
    }
}

让它工作的唯一方法是将文件名更改为index.ts

4

1 回答 1

-1

The way you've phrased the question - snowpack 'not taking' your .d.ts files - is a bit vague for me. If you mean that your editor (assuming VSCode) is not giving you autocompletion then try to add the file to the "include" array in your tsconfig.json:

{
    "include": [
        ...
        "index.d.ts",
    ]
}

I found this solution from the basic typescript template used by the create-snowpack-app CLI tool: https://github.com/snowpackjs/snowpack/tree/main/create-snowpack-app/app-template-blank-typescript There the .d.ts file is inside 'types' folder, and that folder is then included in tsconfig.

于 2021-02-07T17:43:01.287 回答