[英]How to copy package.json in dist or build folder when running tsc (TypeScript compiler)
I have a TypeScript React component that uses a package.json
file (see screenshot) and I run tsc
in order to transpile it to es5 in my dist
folder but the package.json
file doesn't get copied.我有一个使用
package.json
文件的 TypeScript React 组件(参见屏幕截图),我运行tsc
以将其转换为dist
文件夹中的 es5,但package.json
文件没有被复制。 Please note that in the screenshot I manually copied it in the dist
folder.请注意,在屏幕截图中,我手动将其复制到了
dist
文件夹中。
So my question: Is there a way to do this via tsc/tsconfig
... without having to add a copy script (ran via yarn build
).所以我的问题:有没有办法通过
tsc/tsconfig
做到这tsc/tsconfig
......而不必添加复制脚本(通过yarn build
)。 Because I would like this to be updated also when running tsc --watch
因为我希望在运行
tsc --watch
时也能更新
Also I do NOT wish to rename my Component.tsx to index.tsx in the component folders.此外,我不希望在组件文件夹中将我的 Component.tsx 重命名为 index.tsx。 I don't want to have 200 index.tsx files in my project and using the
package.json
's main
allow me to have import SomeComponent from './components/SomeComponent'
instead of doing import SomeComponent from './components/SomeComponent/SomeComponent'
so it's great.我不想在我的项目中有 200 个 index.tsx 文件,并且使用
package.json
的main
允许我import SomeComponent from './components/SomeComponent'
import SomeComponent from './components/SomeComponent/SomeComponent'
而不是import SomeComponent from './components/SomeComponent'
import SomeComponent from './components/SomeComponent/SomeComponent'
所以它很棒。
Here is my tsconfig
file:这是我的
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"]
}
Many thanks for your time and your help or suggestions.非常感谢您的时间和您的帮助或建议。
Just include it in your tsconfig.json
file and enable the resolveJsonModule
compiler option.只需将它包含在您的
tsconfig.json
文件中并启用resolveJsonModule
编译器选项。 You can do this by merging the following config into your tsconfig.json
file:您可以通过将以下配置合并到您的
tsconfig.json
文件中来做到这一点:
{
"compilerOptions": {
"resolveJsonModule": true
},
"include": ["./package.json"]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.