/
generate-config.ts
50 lines (47 loc) · 1.42 KB
/
generate-config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type { Tree } from '@nrwl/devkit';
import {
generateFiles,
joinPathFragments,
logger,
offsetFromRoot,
} from '@nrwl/devkit';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import type { Schema } from '../schema';
const SHARED_SINGLETON_LIBRARIES = [
'@angular/core',
'@angular/common',
'@angular/common/http',
'@angular/router',
'rxjs',
];
export function generateWebpackConfig(
host: Tree,
options: Schema,
appRoot: string,
remotesWithPorts: { remoteName: string; port: number }[]
) {
if (
host.exists(`${appRoot}/webpack.config.js`) ||
host.exists(`${appRoot}/webpack.prod.config.js`)
) {
logger.warn(
`NOTE: We encountered an existing webpack config for the app ${options.appName}. We have overwritten this file with the Module Federation Config.\n
If this was not the outcome you expected, you can discard the changes we have made, create a backup of your current webpack config, and run the command again.`
);
}
generateFiles(
host,
joinPathFragments(__dirname, '../files/webpack'),
appRoot,
{
tmpl: '',
type: options.mfeType,
name: options.appName,
remotes: remotesWithPorts ?? [],
sourceRoot: appRoot,
sharedLibraries: SHARED_SINGLETON_LIBRARIES,
offsetFromRoot: offsetFromRoot(appRoot),
rootTsConfigPath: getRelativePathToRootTsConfig(host, appRoot),
}
);
}