Skip to content

Commit 9bb1ff9

Browse files
committed
fix: properly split CJS and ESM
1 parent 67fa540 commit 9bb1ff9

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

package.json

+14-8
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44
"description": "Blazing fast input validation and transformation ⚡",
55
"author": "@sapphire",
66
"license": "MIT",
7-
"main": "dist/index.js",
8-
"module": "dist/index.mjs",
9-
"browser": "dist/index.global.js",
10-
"unpkg": "dist/index.global.js",
11-
"types": "dist/index.d.ts",
7+
"main": "dist/cjs/index.cjs",
8+
"module": "dist/esm/index.mjs",
9+
"browser": "dist/iife/index.global.js",
10+
"unpkg": "dist/iife/index.global.js",
11+
"types": "dist/cjs/index.d.ts",
1212
"exports": {
13-
"types": "./dist/index.d.ts",
14-
"import": "./dist/index.mjs",
15-
"require": "./dist/index.js"
13+
"import": {
14+
"types": "./dist/esm/index.d.mts",
15+
"default": "./dist/esm/index.mjs"
16+
},
17+
"require": {
18+
"types": "./dist/cjs/index.d.ts",
19+
"default": "./dist/cjs/index.cjs"
20+
},
21+
"browser": "./dist/iife/index.global.js"
1622
},
1723
"sideEffects": false,
1824
"homepage": "https://www.sapphirejs.dev",

tsup.config.ts

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
1-
import { defineConfig } from 'tsup';
21
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
2+
import { defineConfig, type Options } from 'tsup';
33

4-
export default defineConfig({
4+
const baseOptions: Options = {
55
clean: true,
66
dts: true,
77
entry: ['src/index.ts'],
8-
format: ['esm', 'cjs', 'iife'],
98
minify: false,
109
skipNodeModulesBundle: true,
1110
sourcemap: true,
1211
target: 'es2020',
1312
tsconfig: 'src/tsconfig.json',
1413
keepNames: true,
15-
globalName: 'SapphireShapeshift',
16-
esbuildPlugins: [nodeModulesPolyfillPlugin()],
1714
treeshake: true
18-
});
15+
};
16+
17+
export default [
18+
defineConfig({
19+
...baseOptions,
20+
outDir: 'dist/cjs',
21+
format: 'cjs',
22+
outExtension: () => ({ js: '.cjs' })
23+
}),
24+
defineConfig({
25+
...baseOptions,
26+
outDir: 'dist/esm',
27+
format: 'esm'
28+
}),
29+
defineConfig({
30+
...baseOptions,
31+
globalName: 'SapphireShapeshift',
32+
esbuildPlugins: [nodeModulesPolyfillPlugin()],
33+
dts: false,
34+
outDir: 'dist/iife',
35+
format: 'iife'
36+
})
37+
];

0 commit comments

Comments
 (0)