Skip to content

Commit d1aa413

Browse files
committed
feat(ui): Switch to ESM only builds
1 parent d444a25 commit d1aa413

File tree

4 files changed

+328
-56
lines changed

4 files changed

+328
-56
lines changed

packages/themes/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"outDir": "dist",
44
"baseUrl": ".",
55
"lib": ["es6", "dom"],
6-
"module": "nodenext",
7-
"moduleResolution": "nodenext",
6+
"module": "ESNext",
7+
"moduleResolution": "bundler",
88
"importHelpers": true,
99
"declaration": true,
1010
"declarationMap": false,

packages/ui/package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,21 @@
1010
"license": "MIT",
1111
"author": "Clerk",
1212
"sideEffects": false,
13+
"type": "module",
1314
"exports": {
1415
".": {
1516
"types": "./dist/types/index.d.ts",
1617
"import": "./dist/ui.mjs",
17-
"require": "./dist/ui.js",
1818
"default": "./dist/ui.mjs"
1919
},
2020
"./entry": {
2121
"types": "./dist/types/entry.d.ts",
2222
"import": "./dist/entry.mjs",
23-
"require": "./dist/entry.js",
2423
"default": "./dist/entry.mjs"
2524
},
2625
"./internal": {
2726
"types": "./dist/types/internal.d.ts",
2827
"import": "./dist/ui.mjs",
29-
"require": "./dist/ui.js",
3028
"default": "./dist/ui.mjs"
3129
},
3230
"./package.json": "./package.json"
@@ -37,14 +35,14 @@
3735
],
3836
"scripts": {
3937
"build": "pnpm build:bundle && pnpm build:declarations",
40-
"build:analyze": "rspack build --config rspack.config.js --env production --analyze",
41-
"build:bundle": "rspack build --config rspack.config.js --env production",
38+
"build:analyze": "rspack build --config rspack.config.mjs --env production --analyze",
39+
"build:bundle": "rspack build --config rspack.config.mjs --env production",
4240
"build:declarations": "tsc -p tsconfig.declarations.json",
4341
"bundlewatch": "FORCE_COLOR=1 bundlewatch --config bundlewatch.config.json",
4442
"bundlewatch:fix": "node bundlewatch-fix.mjs",
4543
"clean": "rimraf ./dist",
46-
"dev": "rspack serve --config rspack.config.js",
47-
"dev:origin": "rspack serve --config rspack.config.js --env devOrigin=http://localhost:${PORT:-4001}",
44+
"dev": "rspack serve --config rspack.config.mjs",
45+
"dev:origin": "rspack serve --config rspack.config.mjs --env devOrigin=http://localhost:${PORT:-4001}",
4846
"format": "node ../../scripts/format-package.mjs",
4947
"format:check": "node ../../scripts/format-package.mjs --check",
5048
"lint": "eslint src",

packages/ui/rspack.config.js

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
// @ts-check
2-
const rspack = require('@rspack/core');
3-
const packageJSON = require('./package.json');
4-
const path = require('path');
5-
const { merge } = require('webpack-merge');
6-
const ReactRefreshPlugin = require('@rspack/plugin-react-refresh');
7-
const { svgLoader, typescriptLoaderProd, typescriptLoaderDev } = require('../../scripts/rspack-common');
2+
import rspack from '@rspack/core';
3+
import packageJSON from './package.json' with { type: 'json' };
4+
import path from 'path';
5+
import { fileURLToPath } from 'url';
6+
import { merge } from 'webpack-merge';
7+
import ReactRefreshPlugin from '@rspack/plugin-react-refresh';
8+
import { svgLoader, typescriptLoaderProd, typescriptLoaderDev } from '../../scripts/rspack-common.js';
9+
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
812

913
const isProduction = mode => mode === 'production';
1014
const isDevelopment = mode => !isProduction(mode);
@@ -228,23 +232,6 @@ const prodConfig = mode => {
228232
},
229233
});
230234

231-
// CJS module bundle (no chunks)
232-
const uiCjs = merge(entryForVariant(variants.ui), common({ mode, variant: variants.ui }), commonForProdBundled(), {
233-
output: {
234-
filename: '[name].js',
235-
libraryTarget: 'commonjs',
236-
},
237-
plugins: [
238-
// Bundle everything into a single file for CJS
239-
new rspack.optimize.LimitChunkCountPlugin({
240-
maxChunks: 1,
241-
}),
242-
],
243-
optimization: {
244-
splitChunks: false,
245-
},
246-
});
247-
248235
// Entry ESM module bundle (no chunks)
249236
const entryEsm = merge(
250237
entryForVariant(variants.entry),
@@ -270,29 +257,7 @@ const prodConfig = mode => {
270257
},
271258
);
272259

273-
// Entry CJS module bundle (no chunks)
274-
const entryCjs = merge(
275-
entryForVariant(variants.entry),
276-
common({ mode, variant: variants.entry }),
277-
commonForProdBundled(),
278-
{
279-
output: {
280-
filename: '[name].js',
281-
libraryTarget: 'commonjs',
282-
},
283-
plugins: [
284-
// Bundle everything into a single file for CJS
285-
new rspack.optimize.LimitChunkCountPlugin({
286-
maxChunks: 1,
287-
}),
288-
],
289-
optimization: {
290-
splitChunks: false,
291-
},
292-
},
293-
);
294-
295-
return [uiBrowser, uiEsm, uiCjs, entryEsm, entryCjs];
260+
return [uiBrowser, uiEsm, entryEsm];
296261
};
297262

298263
/**
@@ -338,7 +303,7 @@ const devConfig = (mode, env) => {
338303
});
339304
};
340305

341-
module.exports = env => {
306+
export default env => {
342307
const mode = env.production ? 'production' : 'development';
343308
return isProduction(mode) ? prodConfig(mode) : devConfig(mode, env);
344309
};

0 commit comments

Comments
 (0)