Skip to content

Commit 91407b0

Browse files
committed
Add native ESM support (#130)
1 parent 053618d commit 91407b0

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

package.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22
"name": "@wojtekmaj/react-async-button",
33
"version": "1.4.0",
44
"description": "A button that handles Promises for your React app.",
5-
"main": "dist/cjs/index.js",
6-
"module": "dist/esm/index.js",
7-
"source": "src/index.ts",
8-
"types": "dist/cjs/index.d.ts",
5+
"type": "module",
6+
"sideEffects": false,
7+
"main": "./dist/cjs/index.js",
8+
"module": "./dist/esm/index.js",
9+
"source": "./src/index.ts",
10+
"types": "./dist/cjs/index.d.ts",
11+
"exports": {
12+
".": {
13+
"import": "./dist/esm/index.js",
14+
"require": "./dist/cjs/index.js"
15+
},
16+
"./src": "./src/index.ts"
17+
},
918
"scripts": {
10-
"build": "yarn build-esm && yarn build-cjs",
19+
"build": "yarn build-esm && yarn build-cjs && yarn build-cjs-package",
1120
"build-esm": "tsc --project tsconfig.build.json --outDir dist/esm --module esnext",
1221
"build-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs",
22+
"build-cjs-package": "echo '{\n \"type\": \"commonjs\"\n}' > dist/cjs/package.json",
1323
"clean": "rimraf dist",
1424
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
1525
"postinstall": "husky install",
@@ -18,7 +28,7 @@
1828
"test": "yarn lint && yarn tsc && yarn prettier && yarn unit",
1929
"tsc": "tsc --noEmit",
2030
"unit": "vitest",
21-
"watch": "yarn build-esm --watch & yarn build-cjs --watch"
31+
"watch": "yarn build-esm --watch & yarn build-cjs --watch & yarn build-cjs-package"
2232
},
2333
"keywords": [
2434
"react",

src/AsyncButton.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { createRef } from 'react';
33
import { act, render, screen } from '@testing-library/react';
44
import userEvent from '@testing-library/user-event';
55

6-
import AsyncButton from './index';
6+
import AsyncButton from './index.js';
77

88
vi.useFakeTimers();
99

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import AsyncButton from './AsyncButton';
1+
import AsyncButton from './AsyncButton.js';
22

3-
export type { AsyncButtonProps } from './AsyncButton';
3+
export type { AsyncButtonProps } from './AsyncButton.js';
44

55
export { AsyncButton };
66

test/Test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import AsyncButton from '@wojtekmaj/react-async-button/src';
33

44
import './Test.css';
55

6-
import { Button } from './button.styles';
6+
import { Button } from './button.styles.js';
77

88
const pendingConfig = {
99
children: 'Loading…',

test/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { StrictMode } from 'react';
22
import { createRoot } from 'react-dom/client';
33

4-
import Test from './Test';
4+
import Test from './Test.js';
55

66
createRoot(document.getElementById('react-root') as HTMLDivElement).render(
77
<StrictMode>

0 commit comments

Comments
 (0)