I am starting a new library in Typescript and React.
But there something wrong on my tsconfig, because when I look at dist
directory, there is only the typescript definitions, and no code in javascript, all code was removed!
My tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "es6",
"lib": ["es6", "dom"],
"allowJs": true,
"jsx": "react",
"declaration": true,
"emitDeclarationOnly": true,
"declarationMap": true,
"outDir": "dist",
"rootDir": "lib",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["lib/**/*.spec.tsx", "lib/**/*.stories.tsx", "lib/**/*.styles.tsx", "lib/settings/*.ts", "dist/**/*"]
}
Here a example of the output file (in dist directory)
Button.d.ts
import React from 'react';
export declare class ButtonProps {
label: string;
buttonStyle: 'default' | 'primary';
disabled: boolean;
iconLeft: string;
iconRight: string;
}
declare const Button: React.FunctionComponent<ButtonProps>;
export default Button;
//# sourceMappingURL=Button.d.ts.map
And there is no code in any of the other files!
What I did wrong? All code was gone on build (building with tsc
), there only the type definitions.
Solved changing the tsconfig to
{
"exclude": ["lib/**/*.spec.tsx", "lib/**/*.stories.tsx", "lib/**/*.styles.tsx", "dist/**/*"],
"compilerOptions": {
"skipLibCheck": true,
"target": "es6",
"module": "es6",
"lib": ["es6", "dom"],
"jsx": "react",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "dist",
"rootDirs": ["lib"],
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
}
}