diff --git a/packages/cli/src/lib/bundler/backend.ts b/packages/cli/src/lib/bundler/backend.ts index e6d2ff3428..6a15c8e35f 100644 --- a/packages/cli/src/lib/bundler/backend.ts +++ b/packages/cli/src/lib/bundler/backend.ts @@ -34,10 +34,9 @@ export async function serveBackend(options: ServeOptions) { poll: true, }, (err: Error) => { - console.log('Build succeeded'); if (err) { console.error(err); - } + } else console.log('Build succeeded'); }, ); diff --git a/packages/cli/src/lib/bundler/bundle.ts b/packages/cli/src/lib/bundler/bundle.ts index ad1a63ebaf..a088202fa8 100644 --- a/packages/cli/src/lib/bundler/bundle.ts +++ b/packages/cli/src/lib/bundler/bundle.ts @@ -40,6 +40,7 @@ export async function buildBundle(options: BuildOptions) { ...options, checksEnabled: false, isDev: false, + isBackend: false, }); const compiler = webpack(config); diff --git a/packages/cli/src/lib/bundler/config.ts b/packages/cli/src/lib/bundler/config.ts index 608f2d7b91..241ef6a9af 100644 --- a/packages/cli/src/lib/bundler/config.ts +++ b/packages/cli/src/lib/bundler/config.ts @@ -79,39 +79,40 @@ export function createConfig( }), ); + const backendRelatedConfig = { + watch: true, + watchOptions: { + ignored: [/node_modules\/(?!\@backstage)/], + }, + externals: [ + nodeExternals({ + modulesDir: paths.rootNodeModules, + whitelist: [ + 'webpack/hot/poll?100', + /\@backstage\/.*\/(?!node_modules)/, + ], + }), + nodeExternals({ + modulesDir: paths.targetNodeModules, + whitelist: [ + 'webpack/hot/poll?100', + /\@backstage\/.*\/(?!node_modules)/, + ], + }), + ], + target: 'node' as const, + node: { + __dirname: true, + __filename: true, + global: true, + }, + }; + return { mode: isDev ? 'development' : 'production', profile: false, ...(isBackend - ? { - watch: true, - watchOptions: { - ignored: [/node_modules\/(?!\@backstage)/], - // poll: 1000 - }, - externals: [ - nodeExternals({ - modulesDir: paths.rootNodeModules, - whitelist: [ - 'webpack/hot/poll?100', - /\@backstage\/.*\/(?!node_modules)/, - ], - }), - nodeExternals({ - modulesDir: paths.targetNodeModules, - whitelist: [ - 'webpack/hot/poll?100', - /\@backstage\/.*\/(?!node_modules)/, - ], - }), - ], - target: 'node', - node: { - __dirname: true, - __filename: true, - global: true, - }, - } + ? backendRelatedConfig : { node: { module: 'empty', @@ -140,7 +141,6 @@ export function createConfig( resolve: { extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx'], mainFields: ['main:src', 'browser', 'module', 'main'], - modules: [paths.targetNodeModules, paths.rootNodeModules], plugins: [ new ModuleScopePlugin( [paths.targetSrc, paths.targetDev], diff --git a/packages/cli/src/lib/bundler/server.ts b/packages/cli/src/lib/bundler/server.ts index bf78c9b9fb..a004bee1a9 100644 --- a/packages/cli/src/lib/bundler/server.ts +++ b/packages/cli/src/lib/bundler/server.ts @@ -38,7 +38,11 @@ export async function serveBundle(options: ServeOptions) { const paths = resolveBundlingPaths(options); const pkgPath = paths.targetPackageJson; const pkg = await fs.readJson(pkgPath); - const config = createConfig(paths, { ...options, isDev: true }); + const config = createConfig(paths, { + ...options, + isDev: true, + isBackend: false, + }); const compiler = webpack(config); const server = new WebpackDevServer(compiler, { diff --git a/packages/cli/src/lib/bundler/types.ts b/packages/cli/src/lib/bundler/types.ts index b375897fc9..62737374bd 100644 --- a/packages/cli/src/lib/bundler/types.ts +++ b/packages/cli/src/lib/bundler/types.ts @@ -22,7 +22,7 @@ export type BundlingOptions = { isDev: boolean; config: Config; appConfigs: AppConfig[]; - isBackend?: boolean; + isBackend: boolean; }; export type ServeOptions = BundlingPathsOptions & {