cli: revert rspack additions to backend bundling
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user