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. Please note that in the screenshot I manually copied it in the dist
folder.
So my question: Is there a way to do this via tsc/tsconfig
... without having to add a copy script (ran via yarn build
). Because I would like this to be updated also when running tsc --watch
Also I do NOT wish to rename my Component.tsx to index.tsx in the component folders. 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.
Here is my tsconfig
file:
{
"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.
Running tsc locally will compile the closest project defined by a tsconfig. json , you can compile a set of TypeScript files by passing in a glob of files you want.
The presence of a tsconfig. json file in a directory indicates that the directory is the root of a TypeScript project. The tsconfig. json file specifies the root files and the compiler options required to compile the project.
Just include it in your tsconfig.json
file and enable the resolveJsonModule
compiler option. You can do this by merging the following config into your tsconfig.json
file:
{
"compilerOptions": {
"resolveJsonModule": true
},
"include": ["./package.json"]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With