运行 tsc(TypeScript 编译器)时如何在 dist 或 build 文件夹中复制 package.json
How to copy package.json in dist or build folder when running tsc (TypeScript compiler)
我有一个使用 package.json
文件的 TypeScript React 组件(见屏幕截图),我 运行 tsc
为了 t运行spile 它到 es5我的 dist
文件夹,但 package.json
文件没有被复制。请注意,在屏幕截图中,我将其手动复制到 dist
文件夹中。
所以我的问题是:有没有一种方法可以通过 tsc/tsconfig
执行此操作...而无需添加复制脚本(运行 通过 yarn build
)。因为我希望在 运行ning tsc --watch
时也能更新
我也不想在组件文件夹中将我的 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"]
}
非常感谢您的宝贵时间以及您的帮助或建议。
只需将其包含在您的 tsconfig.json
文件中并启用 resolveJsonModule
编译器选项。您可以通过将以下配置合并到您的 tsconfig.json
文件中来执行此操作:
{
"compilerOptions": {
"resolveJsonModule": true
},
"include": ["./package.json"]
}
我有一个使用 package.json
文件的 TypeScript React 组件(见屏幕截图),我 运行 tsc
为了 t运行spile 它到 es5我的 dist
文件夹,但 package.json
文件没有被复制。请注意,在屏幕截图中,我将其手动复制到 dist
文件夹中。
所以我的问题是:有没有一种方法可以通过 tsc/tsconfig
执行此操作...而无需添加复制脚本(运行 通过 yarn build
)。因为我希望在 运行ning tsc --watch
我也不想在组件文件夹中将我的 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"]
}
非常感谢您的宝贵时间以及您的帮助或建议。
只需将其包含在您的 tsconfig.json
文件中并启用 resolveJsonModule
编译器选项。您可以通过将以下配置合并到您的 tsconfig.json
文件中来执行此操作:
{
"compilerOptions": {
"resolveJsonModule": true
},
"include": ["./package.json"]
}