Merge pull request #2224 from spotify/rugvip/allback

cli: mark all monorepo packages as external, instead of @backstage ones
This commit is contained in:
Patrik Oldsberg
2020-09-02 11:16:01 +02:00
committed by GitHub
3 changed files with 16 additions and 10 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ export async function serveBackend(
},
) {
const paths = resolveBundlingPaths(options);
const config = createBackendConfig(paths, {
const config = await createBackendConfig(paths, {
...options,
isDev: true,
});
+15 -8
View File
@@ -15,6 +15,7 @@
*/
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ModuleScopePlugin from 'react-dev-utils/ModuleScopePlugin';
@@ -171,14 +172,23 @@ export async function createConfig(
};
}
export function createBackendConfig(
export async function createBackendConfig(
paths: BundlingPaths,
options: BackendBundlingOptions,
): webpack.Configuration {
): Promise<webpack.Configuration> {
const { checksEnabled, isDev } = options;
const { loaders } = transforms(options);
// Find all local monorepo packages and their node_modules, and mark them as external.
const LernaProject = require('@lerna/project');
const project = new LernaProject(cliPaths.targetDir);
const packages = await project.getPackages();
const localPackageNames = packages.map((p: any) => p.name);
const moduleDirs = packages.map((p: any) =>
resolvePath(p.location, 'node_modules'),
);
return {
mode: isDev ? 'development' : 'production',
profile: false,
@@ -193,11 +203,8 @@ export function createBackendConfig(
externals: [
nodeExternals({
modulesDir: paths.rootNodeModules,
allowlist: ['webpack/hot/poll?100', /\@backstage\/.*/],
}),
nodeExternals({
modulesDir: paths.targetNodeModules,
allowlist: ['webpack/hot/poll?100', /\@backstage\/.*/],
additionalModuleDirs: moduleDirs,
allowlist: ['webpack/hot/poll?100', ...localPackageNames],
}),
],
target: 'node' as const,
@@ -219,7 +226,7 @@ export function createBackendConfig(
resolve: {
extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx'],
mainFields: ['browser', 'module', 'main'],
modules: [paths.targetNodeModules, paths.rootNodeModules],
modules: [paths.rootNodeModules, ...moduleDirs],
plugins: [
new ModuleScopePlugin(
[paths.targetSrc, paths.targetDev],
-1
View File
@@ -63,7 +63,6 @@ export function resolveBundlingPaths(options: BundlingPathsOptions) {
targetDev: paths.resolveTarget('dev'),
targetEntry: resolveTargetModule(entry),
targetTsConfig: paths.resolveTargetRoot('tsconfig.json'),
targetNodeModules: paths.resolveTarget('node_modules'),
targetPackageJson: paths.resolveTarget('package.json'),
rootNodeModules: paths.resolveTargetRoot('node_modules'),
root: paths.targetRoot,