Skip to content

Commit 645f3a0

Browse files
feat(build): add cjs support (#9)
* feat(build): add cjs support * fix(build): add cjs build config file
1 parent cb6215d commit 645f3a0

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

packages/module/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"main": "dist/esm/index.js",
66
"module": "dist/esm/index.js",
77
"scripts": {
8-
"build": "tsc --build --verbose ./tsconfig.json",
8+
"build": "yarn build:esm && yarn build:cjs",
9+
"build:esm": "tsc --build --verbose ./tsconfig.json",
10+
"build:cjs": "tsc --build --verbose ./tsconfig.cjs.json",
911
"clean": "rimraf dist",
1012
"docs:develop": "pf-docs-framework start",
1113
"docs:build": "pf-docs-framework build all --output public",

packages/module/tsconfig.cjs.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./dist/js",
5+
"module": "commonjs",
6+
"tsBuildInfoFile": "dist/cjs.tsbuildinfo"
7+
}
8+
}

packages/module/tsconfig.json

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
// "checkJs": true, /* Report errors in .js files. */
1212
"jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */,
1313
"declaration": true /* Generates corresponding '.d.ts' file. */,
14-
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15-
// "sourceMap": true, /* Generates corresponding '.map' file. */
14+
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15+
"sourceMap": true, /* Generates corresponding '.map' file. */
1616
// "outFile": "./", /* Concatenate and emit output to single file. */
1717
"outDir": "./dist/esm" /* Redirect output structure to the directory. */,
1818
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
19-
// "composite": true, /* Enable project compilation */
19+
"composite": true, /* Enable project compilation */
2020
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
2121
// "removeComments": true, /* Do not emit comments to output. */
2222
// "noEmit": true, /* Do not emit outputs. */
23-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
23+
"importHelpers": true, /* Import emit helpers from 'tslib'. */
2424
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25-
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
25+
"isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
2626

2727
/* Strict Type-Checking Options */
2828
"strict": true /* Enable all strict type-checking options. */,
@@ -67,7 +67,16 @@
6767

6868
/* Advanced Options */
6969
"skipLibCheck": true /* Skip type checking of declaration files. */,
70-
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
70+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
71+
"plugins": [
72+
{ "transform": "transformer-cjs-imports" }
73+
]
7174
},
72-
"include": ["./src/*", "./src/**/*"]
75+
"include": ["./src/*", "./src/**/*"],
76+
"exclude": [
77+
"**/**.test.tsx",
78+
"**/**.test.ts",
79+
"**/examples/**",
80+
"**/__mocks__/**"
81+
]
7382
}

0 commit comments

Comments
 (0)