Skip to content

Commit 2b2dd16

Browse files
authored
chore: merge build config for core package (#3868)
1 parent d75b8fd commit 2b2dd16

File tree

2 files changed

+62
-112
lines changed

2 files changed

+62
-112
lines changed

packages/core/modern.config.ts

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,60 @@
1-
import { defineConfig, moduleTools } from '@modern-js/module-tools';
1+
import fs from 'node:fs';
2+
import path from 'node:path';
23
import {
3-
BUILD_TARGET,
4-
cjsBuildConfig,
5-
commonExternals,
6-
emitTypePkgJsonPlugin,
7-
esmBuildConfig,
8-
} from '@rsbuild/config/modern.config.ts';
4+
type CliPlugin,
5+
type ModuleTools,
6+
defineConfig,
7+
moduleTools,
8+
} from '@modern-js/module-tools';
99
import prebundleConfig from './prebundle.config.mjs';
1010

11+
const define = {
12+
RSBUILD_VERSION: require('../../packages/core/package.json').version,
13+
};
14+
15+
const BUILD_TARGET = {
16+
node: 'es2021',
17+
client: 'es2017',
18+
} as const;
19+
20+
const requireShim = {
21+
// use import.meta['url'] to bypass bundle-require replacement of import.meta.url
22+
js: `import { createRequire } from 'module';
23+
var require = createRequire(import.meta['url']);\n`,
24+
};
25+
26+
const emitTypePkgJsonPlugin: CliPlugin<ModuleTools> = {
27+
name: 'emit-type-pkg-json-plugin',
28+
29+
setup() {
30+
return {
31+
afterBuild() {
32+
const typesDir = path.join(process.cwd(), 'dist-types');
33+
const pkgPath = path.join(typesDir, 'package.json');
34+
if (!fs.existsSync(typesDir)) {
35+
fs.mkdirSync(typesDir);
36+
}
37+
fs.writeFileSync(
38+
pkgPath,
39+
JSON.stringify({
40+
'//': 'This file is for making TypeScript work with moduleResolution node16+.',
41+
version: '1.0.0',
42+
}),
43+
'utf8',
44+
);
45+
},
46+
};
47+
},
48+
};
49+
1150
const externals = [
12-
...commonExternals,
51+
'webpack',
52+
'@rspack/core',
53+
'@rsbuild/core',
1354
'@rsbuild/core/client/hmr',
1455
'@rsbuild/core/client/overlay',
56+
/[\\/]compiled[\\/]/,
57+
/node:/,
1558
];
1659

1760
const aliasCompiledPlugin = {
@@ -33,7 +76,12 @@ export default defineConfig({
3376
buildConfig: [
3477
// Node / ESM
3578
{
36-
...esmBuildConfig,
79+
format: 'esm',
80+
target: BUILD_TARGET.node,
81+
define,
82+
autoExtension: true,
83+
shims: true,
84+
banner: requireShim,
3785
input: ['src/index.ts'],
3886
externals,
3987
dts: false,
@@ -44,7 +92,11 @@ export default defineConfig({
4492
},
4593
// Node / CJS
4694
{
47-
...cjsBuildConfig,
95+
format: 'cjs',
96+
target: BUILD_TARGET.node,
97+
define,
98+
autoExtension: true,
99+
dts: false,
48100
input: [
49101
'src/index.ts',
50102
'src/loader/ignoreCssLoader.ts',

scripts/config/modern.config.ts

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)