Skip to content

Commit 2115052

Browse files
committed
Add native ESM support
1 parent c453f27 commit 2115052

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

package.json

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@
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": {
1019
"build": "yarn build-esm && yarn build-cjs",
1120
"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",
21+
"build-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs && echo '{\n \"type\": \"commonjs\"\n}' > dist/cjs/package.json",
1322
"clean": "rimraf dist",
1423
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
1524
"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: 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)