Skip to content

Commit 00586d5

Browse files
committed
Add native ESM support
1 parent 877f37b commit 00586d5

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
"name": "@wojtekmaj/react-async-button",
33
"version": "1.3.1",
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+
"import": "./dist/esm/index.js",
13+
"require": "./dist/cjs/index.js"
14+
},
915
"scripts": {
1016
"build": "yarn build-esm && yarn build-cjs",
1117
"build-esm": "tsc --project tsconfig.build.json --outDir dist/esm --module esnext",
12-
"build-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs",
18+
"build-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs && echo '{\n \"type\": \"commonjs\"\n}' > dist/cjs/package.json",
1319
"clean": "rimraf dist",
1420
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
1521
"postinstall": "husky install",

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
2-
import AsyncButton from '@wojtekmaj/react-async-button/src';
2+
import AsyncButton from '@wojtekmaj/react-async-button/src/index.js';
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)