Skip to content

Commit 19e76a3

Browse files
authored
Merge pull request #10 from scottrippey/esm
Support ESM
2 parents 86f0966 + 8a4a25c commit 19e76a3

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- npm run test:react-18
2323
- npm run test:react-17
2424
- npm run lint
25-
- npm run build:check
25+
- npm run typecheck
2626
steps:
2727
- uses: actions/checkout@v3
2828
- uses: actions/setup-node@v3

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@
22
"name": "react-use-event-hook",
33
"version": "0.9.2",
44
"description": "Same as React's `useCallback`, but returns a stable reference.",
5-
"main": "dist/useEvent.js",
5+
"main": "dist/cjs/useEvent.js",
6+
"module": "dist/esm/useEvent.js",
7+
"types": "dist/esm/useEvent.d.ts",
68
"files": [
79
"dist",
810
"src"
911
],
1012
"scripts": {
11-
"check": "npm run lint && npm run build:check && npm run test:react-18 && npm run test:react-17",
13+
"check": "npm run lint && npm run typecheck && npm run test:react-18 && npm run test:react-17",
1214
"test": "jest",
1315
"test:react-18": "jest",
1416
"test:react-17": "cd test/react-17; test -d node_modules || npm ci; npm run test",
1517
"test:watch": "jest --watch",
1618
"lint": "prettier src --check",
1719
"lint:fix": "prettier src --write",
18-
"build": "npm run clean && tsc",
20+
"build": "npm run clean && npm run build:esm && npm run build:cjs",
21+
"build:esm": "tsc",
22+
"build:cjs": "tsc --outDir dist/cjs --module commonjs",
1923
"clean": "rimraf dist",
2024
"build:watch": "tsc --watch",
21-
"build:check": "tsc --noEmit",
25+
"typecheck": "tsc --noEmit",
2226
"prepublishOnly": "npm run build",
23-
"preversion": "npm run test && npm run build:check"
27+
"preversion": "npm run test && npm run typecheck"
2428
},
2529
"repository": {
2630
"type": "git",

tsconfig.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
/* Basic Options */
66
// "incremental": true, /* Enable incremental compilation */
7-
"target": "ES5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8-
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
7+
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8+
"module": "ES2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
99
// "lib": [], /* Specify library files to be included in the compilation. */
1010
// "allowJs": true, /* Allow javascript files to be compiled. */
1111
// "checkJs": true, /* Report errors in .js files. */
@@ -14,7 +14,7 @@
1414
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
1515
"sourceMap": true, /* Generates corresponding '.map' file. */
1616
// "outFile": "./", /* Concatenate and emit output to single file. */
17-
"outDir": "dist", /* Redirect output structure to the directory. */
17+
"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. */
1919
// "composite": true, /* Enable project compilation */
2020
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
@@ -52,7 +52,7 @@
5252
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
5353
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
5454
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
55-
"resolveJsonModule": true,
55+
// "resolveJsonModule": true,
5656

5757
/* Source Map Options */
5858
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
@@ -69,6 +69,7 @@
6969
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
7070
},
7171
"exclude": [
72-
"**/*.test.*"
72+
"**/*.test*",
73+
"dist/**"
7374
]
7475
}

0 commit comments

Comments
 (0)