cli: revert rspack additions to backend bundling

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-10-11 00:36:51 +02:00
parent 551abf6d55
commit 7357f79670
2 changed files with 10 additions and 22 deletions
+1 -8
View File
@@ -20,24 +20,17 @@ import { resolveBundlingPaths } from './paths';
import { BackendServeOptions } from './types';
export async function serveBackend(options: BackendServeOptions) {
const useRspack = !!process.env.EXPERIMENTAL_RSPACK;
const paths = resolveBundlingPaths(options);
const config = await createBackendConfig(paths, {
...options,
isDev: true,
useRspack,
});
// Webpack only replaces occurrences of this in code it touches, which does
// not include dependencies in node_modules. So we set it here at runtime as well.
(process.env as { NODE_ENV: string }).NODE_ENV = 'development';
const bundler: typeof webpack = useRspack
? require('@rspack/core').rspack
: webpack;
const compiler = bundler(config, (err: Error | null) => {
const compiler = webpack(config, (err: Error | null) => {
if (err) {
console.error(err);
} else console.log('Build succeeded');
+9 -14
View File
@@ -447,7 +447,7 @@ export async function createBackendConfig(
paths: BundlingPaths,
options: BackendBundlingOptions,
): Promise<webpack.Configuration> {
const { checksEnabled, isDev, useRspack } = options;
const { checksEnabled, isDev } = options;
// Find all local monorepo packages and their node_modules, and mark them as external.
const { packages } = await getPackages(cliPaths.targetDir);
@@ -518,16 +518,13 @@ export async function createBackendConfig(
extensions: ['.ts', '.mjs', '.js', '.json'],
mainFields: ['main'],
modules: [paths.rootNodeModules, ...moduleDirs],
// FIXME: see also https://github.com/web-infra-dev/rspack/issues/3408
...(!useRspack && {
plugins: [
new LinkedPackageResolvePlugin(paths.rootNodeModules, externalPkgs),
new ModuleScopePlugin(
[paths.targetSrc, paths.targetDev],
[paths.targetPackageJson],
),
],
}),
plugins: [
new LinkedPackageResolvePlugin(paths.rootNodeModules, externalPkgs),
new ModuleScopePlugin(
[paths.targetSrc, paths.targetDev],
[paths.targetPackageJson],
),
],
},
module: {
rules: loaders,
@@ -554,9 +551,7 @@ export async function createBackendConfig(
nodeArgs: runScriptNodeArgs.length > 0 ? runScriptNodeArgs : undefined,
args: process.argv.slice(3), // drop `node backstage-cli backend:dev`
}),
new (useRspack
? require('@rspack/core').rspack.HotModuleReplacementPlugin
: webpack.HotModuleReplacementPlugin)(),
new webpack.HotModuleReplacementPlugin(),
...(checksEnabled
? [
new ForkTsCheckerWebpackPlugin({