Skip to content

Commit d75b8fd

Browse files
authored
feat(webpack): use Rslib to bundle (#3713)
1 parent dc5be32 commit d75b8fd

File tree

19 files changed

+85
-61
lines changed

19 files changed

+85
-61
lines changed

e2e/cases/config/inspect-config/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3-
import { createRsbuild } from '@e2e/helper';
3+
import { createRsbuild, rspackOnlyTest } from '@e2e/helper';
44
import { expect, test } from '@playwright/test';
55

66
const rsbuildConfig = path.resolve(
@@ -106,7 +106,7 @@ test('should not generate config files when writeToDisk is false', async () => {
106106
expect(fs.existsSync(bundlerConfig)).toBeFalsy();
107107
});
108108

109-
test('should allow to specify absolute output path', async () => {
109+
rspackOnlyTest('should allow to specify absolute output path', async () => {
110110
const rsbuild = await createRsbuild({
111111
cwd: __dirname,
112112
});

packages/compat/webpack/modern.config.ts

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

packages/compat/webpack/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@
1111
"type": "module",
1212
"exports": {
1313
".": {
14-
"types": "./dist-types/index.d.ts",
14+
"types": "./dist/index.d.ts",
1515
"import": "./dist/index.js",
1616
"require": "./dist/index.cjs"
1717
}
1818
},
1919
"main": "./dist/index.cjs",
20-
"types": "./dist-types/index.d.ts",
20+
"types": "./dist/index.d.ts",
2121
"files": [
2222
"static",
23-
"dist",
24-
"dist-types"
23+
"dist"
2524
],
2625
"scripts": {
27-
"build": "modern build",
28-
"dev": "modern build --watch"
26+
"build": "rslib build",
27+
"dev": "rslib build --watch"
2928
},
3029
"dependencies": {
3130
"copy-webpack-plugin": "11.0.0",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import path from 'node:path';
2+
import { pureEsmPackage } from '@rsbuild/config/rslib.config.ts';
3+
import { defineConfig } from '@rslib/core';
4+
5+
export default defineConfig({
6+
...pureEsmPackage,
7+
output: {
8+
...pureEsmPackage.output,
9+
copy: [
10+
{
11+
from: path.resolve(__dirname, 'src/index.cjs'),
12+
},
13+
],
14+
},
15+
});

packages/compat/webpack/src/build.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { logger } from '@rsbuild/core';
22
import type { Build, BuildOptions, Rspack } from '@rsbuild/core';
33
import type { Configuration as WebpackConfig } from 'webpack';
44
import WebpackMultiStats from 'webpack/lib/MultiStats.js';
5-
import { createCompiler } from './createCompiler';
6-
import type { InitConfigsOptions } from './initConfigs';
7-
import { registerBuildHook } from './shared';
5+
import { createCompiler } from './createCompiler.js';
6+
import type { InitConfigsOptions } from './initConfigs.js';
7+
import { registerBuildHook } from './shared.js';
88

99
export const build = async (
1010
initOptions: InitConfigsOptions,

packages/compat/webpack/src/createCompiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type Rspack, logger } from '@rsbuild/core';
22
import WebpackMultiStats from 'webpack/lib/MultiStats.js';
3-
import { type InitConfigsOptions, initConfigs } from './initConfigs';
4-
import { formatStats, getStatsOptions, registerDevHook } from './shared';
3+
import { type InitConfigsOptions, initConfigs } from './initConfigs.js';
4+
import { formatStats, getStatsOptions, registerDevHook } from './shared.js';
55

66
export async function createCompiler(options: InitConfigsOptions) {
77
logger.debug('create compiler');
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* CommonJS wrapper
3+
*/
4+
module.exports.webpackProvider = (...args) =>
5+
import('./index.js').then((i) => i.webpackProvider(...args));
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export { webpackProvider } from './provider';
1+
export { webpackProvider } from './provider.js';
22
export type {
33
// Third Party Types
44
webpack,
55
WebpackConfig,
6-
} from './types';
6+
} from './types.js';

packages/compat/webpack/src/initConfigs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {
44
type ResolvedCreateRsbuildOptions,
55
logger,
66
} from '@rsbuild/core';
7-
import { inspectConfig } from './inspectConfig';
8-
import { type InternalContext, initRsbuildConfig } from './shared';
9-
import type { WebpackConfig } from './types';
10-
import { generateWebpackConfig } from './webpackConfig';
7+
import { inspectConfig } from './inspectConfig.js';
8+
import { type InternalContext, initRsbuildConfig } from './shared.js';
9+
import type { WebpackConfig } from './types.js';
10+
import { generateWebpackConfig } from './webpackConfig.js';
1111

1212
export type InitConfigsOptions = {
1313
context: InternalContext;

packages/compat/webpack/src/inspectConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { isAbsolute, join } from 'node:path';
22
import type { InspectConfigOptions, InspectConfigResult } from '@rsbuild/core';
3-
import { type InitConfigsOptions, initConfigs } from './initConfigs';
3+
import { type InitConfigsOptions, initConfigs } from './initConfigs.js';
44
import {
55
type InternalContext,
66
getRsbuildInspectConfig,
77
outputInspectConfigFiles,
88
stringifyConfig,
9-
} from './shared';
10-
import type { WebpackConfig } from './types';
9+
} from './shared.js';
10+
import type { WebpackConfig } from './types.js';
1111

1212
const getInspectOutputPath = (
1313
context: InternalContext,

0 commit comments

Comments
 (0)