Skip to content

Commit 444a2e5

Browse files
committed
fix(build): fix path error when appConfig has no main
1 parent 45e2985 commit 444a2e5

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

packages/angular-cli/models/webpack-build-common.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ export function getWebpackCommonConfig(
3535
) {
3636

3737
const appRoot = path.resolve(projectRoot, appConfig.root);
38-
const appMain = path.resolve(appRoot, appConfig.main);
3938
const nodeModules = path.resolve(projectRoot, 'node_modules');
4039

4140
let extraPlugins: any[] = [];
4241
let extraRules: any[] = [];
4342
let lazyChunks: string[] = [];
4443

45-
let entryPoints: { [key: string]: string[] } = {
46-
main: [appMain]
47-
};
44+
let entryPoints: { [key: string]: string[] } = {};
45+
46+
if (appConfig.main) {
47+
entryPoints['main'] = [path.resolve(appRoot, appConfig.main)];
48+
}
4849

4950
// process global scripts
5051
if (appConfig.scripts && appConfig.scripts.length > 0) {

packages/angular-cli/models/webpack-config.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ export class NgCliWebpackConfig {
3434
progress = true,
3535
deployUrl?: string
3636
) {
37-
const config: CliConfig = CliConfig.fromProject();
38-
const appConfig = config.config.apps[0];
37+
const appConfig = CliConfig.fromProject().config.apps[0];
38+
const projectRoot = this.ngCliProject.root;
3939

4040
appConfig.outDir = outputDir || appConfig.outDir;
4141
appConfig.deployUrl = deployUrl || appConfig.deployUrl;
4242

4343
let baseConfig = getWebpackCommonConfig(
44-
this.ngCliProject.root,
44+
projectRoot,
4545
environment,
4646
appConfig,
4747
baseHref,
@@ -50,28 +50,28 @@ export class NgCliWebpackConfig {
5050
verbose,
5151
progress
5252
);
53-
let targetConfigPartial = this.getTargetConfig(
54-
this.ngCliProject.root, appConfig, sourcemap, verbose
55-
);
56-
const typescriptConfigPartial = isAoT
57-
? getWebpackAotConfigPartial(this.ngCliProject.root, appConfig, i18nFile, i18nFormat, locale)
58-
: getWebpackNonAotConfigPartial(this.ngCliProject.root, appConfig);
53+
let targetConfigPartial = this.getTargetConfig(projectRoot, appConfig, sourcemap, verbose);
5954

6055
if (appConfig.mobile) {
61-
let mobileConfigPartial = getWebpackMobileConfigPartial(this.ngCliProject.root, appConfig);
62-
let mobileProdConfigPartial = getWebpackMobileProdConfigPartial(this.ngCliProject.root,
63-
appConfig);
56+
let mobileConfigPartial = getWebpackMobileConfigPartial(projectRoot, appConfig);
57+
let mobileProdConfigPartial = getWebpackMobileProdConfigPartial(projectRoot, appConfig);
6458
baseConfig = webpackMerge(baseConfig, mobileConfigPartial);
6559
if (this.target == 'production') {
6660
targetConfigPartial = webpackMerge(targetConfigPartial, mobileProdConfigPartial);
6761
}
6862
}
6963

70-
this.config = webpackMerge(
71-
baseConfig,
72-
targetConfigPartial,
73-
typescriptConfigPartial
74-
);
64+
let config = webpackMerge(baseConfig, targetConfigPartial);
65+
66+
if (appConfig.main) {
67+
const typescriptConfigPartial = isAoT
68+
? getWebpackAotConfigPartial(projectRoot, appConfig, i18nFile, i18nFormat, locale)
69+
: getWebpackNonAotConfigPartial(projectRoot, appConfig);
70+
71+
config = webpackMerge(config, typescriptConfigPartial);
72+
}
73+
74+
this.config = config;
7575
}
7676

7777
getTargetConfig(projectRoot: string, appConfig: any, sourcemap: boolean, verbose: boolean): any {

tests/e2e/tests/misc/minimal-config.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { writeFile } from '../../utils/fs';
1+
import { writeFile, writeMultipleFiles } from '../../utils/fs';
22
import { ng } from '../../utils/process';
33

44

@@ -10,5 +10,15 @@ export default function () {
1010
main: 'main.ts'
1111
}]
1212
})))
13+
.then(() => ng('build'))
14+
.then(() => writeMultipleFiles({
15+
'./src/script.js': 'console.log(\'hello\')',
16+
'angular-cli.json': JSON.stringify({
17+
apps: [{
18+
root: 'src',
19+
scripts: ['./script.js']
20+
}]
21+
}),
22+
}))
1323
.then(() => ng('build'));
1424
}

0 commit comments

Comments
 (0)