DekGenius.com
TYPESCRIPT
generate tsconfig
exclude folder from typescript compiler tsconfig.json
{
"compilerOptions": {
...
},
"exclude": ["node_modules", "**/node_modules/*"]
}
tsconfig
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}
typescript tsconfig.json file
{
"compilerOptions": {
"module": "esnext",
"target": "es2016",
"jsx": "react-jsx",
"strictFunctionTypes": true,
"sourceMap": true,
"outDir": "./build",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
},
"exclude": ["node_modules", "**/node_modules/*"],
"include": ["src", "electron/renderer.ts"]
}
init tsconfig file
// source from https://stackoverflow.com/questions/36916989/how-can-i-generate-a-tsconfig-json-file
$ tsc --init
// Try to run in your console the following to check the version:
$ tsc -v
// If the version is older than 1.6 you will need to update:
$ npm install -g typescript
// Remember that you need to install node.js to use npm.
basic tsconfig file
{
"compilerOptions": {
"outDir": "./dist/",
+ "sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"allowJs": true,
"moduleResolution": "node",
}
}
generate tsconfig
[1] $ tsc -v
[2] If the version is older than 1.6:
$ npm install -g typescript
[3] $ tsc --init
tsconfig.json
// mytsconfig.
{
"compilerOptions": {
"allowJs": true,
"checkJs": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"typeRoots": ["src/types", "node_modules/@types"],
"baseUrl": "src",
"paths": {
"@/*": ["*"] // matching @src/* to src/*
},
"outDir": "dist",
"experimentalDecorators": true,
},
"exclude": ["node_modules", "dist"],
"include": ["src/**/*","src/*"]
}
tsconfig resolve require json
{
"compilerOptions": {
// ...
"resolveJsonModule": true,
// ...
}
}
tsconfig.json, Typescript
{
"compilerOptions": {
"experimentalDecorators": true,
"jsxImportSource": "preact"
}
}
pass tsconfig.json to node command
# To force the use of a specific tsconfig.json, use the TS_NODE_PROJECT environment variable
TS_NODE_PROJECT="path/to/tsconfig.json" node --loader ts-node/esm ./my-script.ts
© 2022 Copyright:
DekGenius.com