我有一个使用package.json
文件的TypeScript React组件(见屏幕截图),我运行tsc
以便将其转换为dist
文件夹中的es5,但是package.json
文件没有被复制。请注意,在屏幕截图中,我手动将其复制到dist
文件夹中。
所以我的问题是:有没有办法通过tsc/tsconfig
做到这一点……而不必添加复制脚本(通过yarn build
运行)。因为我希望在运行tsc --watch
时也更新这一点
另外,我不希望在component文件夹中将我的Component.tsx重命名为index.tsx。我不想在我的项目中有200个index.tsx文件,并且使用package.json
的main
可以让我拥有import SomeComponent from './components/SomeComponent'
而不是import SomeComponent from './components/SomeComponent/SomeComponent'
,所以这很棒。
这是我的tsconfig
文件:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"outDir": "dist",
"moduleResolution": "node",
"resolveJsonModule": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"declaration": true,
"jsx": "react"
},
"include": ["src"]
}
非常感谢您的时间和您的帮助或建议。
发布于 2021-04-30 13:04:06
只需将其包含在tsconfig.json
文件中并启用resolveJsonModule
编译器选项即可。您可以通过将以下配置合并到您的tsconfig.json
文件中来完成此操作:
{
"compilerOptions": {
"resolveJsonModule": true
},
"include": ["./package.json"]
}
https://stackoverflow.com/questions/54836908
复制相似问题