Skip to content

Commit 7bd165b

Browse files
authored
fix(build): fix path error when appConfig has no main (#3867)
1 parent 74f7cdd commit 7bd165b

File tree

5 files changed

+58
-30
lines changed

5 files changed

+58
-30
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@ export function getWebpackCommonConfig(
3737
) {
3838

3939
const appRoot = path.resolve(projectRoot, appConfig.root);
40-
const appMain = path.resolve(appRoot, appConfig.main);
4140
const nodeModules = path.resolve(projectRoot, 'node_modules');
4241

4342
let extraPlugins: any[] = [];
4443
let extraRules: any[] = [];
4544
let lazyChunks: string[] = [];
4645

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

5152
// determine hashing format
5253
const hashFormat = getOutputHashFormat(outputHashing);

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

+17-17
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ export class NgCliWebpackConfig {
3535
deployUrl?: string,
3636
outputHashing?: string
3737
) {
38-
const config: CliConfig = CliConfig.fromProject();
39-
const appConfig = config.config.apps[0];
38+
const appConfig = CliConfig.fromProject().config.apps[0];
39+
const projectRoot = this.ngCliProject.root;
4040

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

4444
let baseConfig = getWebpackCommonConfig(
45-
this.ngCliProject.root,
45+
projectRoot,
4646
environment,
4747
appConfig,
4848
baseHref,
@@ -52,28 +52,28 @@ export class NgCliWebpackConfig {
5252
progress,
5353
outputHashing
5454
);
55-
let targetConfigPartial = this.getTargetConfig(
56-
this.ngCliProject.root, appConfig, sourcemap, verbose
57-
);
58-
const typescriptConfigPartial = isAoT
59-
? getWebpackAotConfigPartial(this.ngCliProject.root, appConfig, i18nFile, i18nFormat, locale)
60-
: getWebpackNonAotConfigPartial(this.ngCliProject.root, appConfig);
55+
let targetConfigPartial = this.getTargetConfig(projectRoot, appConfig, sourcemap, verbose);
6156

6257
if (appConfig.mobile) {
63-
let mobileConfigPartial = getWebpackMobileConfigPartial(this.ngCliProject.root, appConfig);
64-
let mobileProdConfigPartial = getWebpackMobileProdConfigPartial(this.ngCliProject.root,
65-
appConfig);
58+
let mobileConfigPartial = getWebpackMobileConfigPartial(projectRoot, appConfig);
59+
let mobileProdConfigPartial = getWebpackMobileProdConfigPartial(projectRoot, appConfig);
6660
baseConfig = webpackMerge(baseConfig, mobileConfigPartial);
6761
if (this.target == 'production') {
6862
targetConfigPartial = webpackMerge(targetConfigPartial, mobileProdConfigPartial);
6963
}
7064
}
7165

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

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

packages/angular-cli/tasks/serve-webpack.ts

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default Task.extend({
5656
entryPoints.push('webpack/hot/dev-server');
5757
config.plugins.push(new webpack.HotModuleReplacementPlugin());
5858
}
59+
if (!config.entry.main) { config.entry.main = []; }
5960
config.entry.main.unshift(...entryPoints);
6061
webpackCompiler = webpack(config);
6162

+30-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { writeFile } from '../../utils/fs';
2-
import { ng } from '../../utils/process';
1+
import { writeFile, writeMultipleFiles } from '../../utils/fs';
2+
import { runServeAndE2e } from '../test/e2e';
33

44

55
export default function () {
@@ -8,7 +8,33 @@ export default function () {
88
apps: [{
99
root: 'src',
1010
main: 'main.ts'
11-
}]
11+
}],
12+
e2e: { protractor: { config: './protractor.conf.js' } }
1213
})))
13-
.then(() => ng('build'));
14+
.then(() => runServeAndE2e())
15+
.then(() => writeMultipleFiles({
16+
'./src/script.js': `
17+
document.querySelector('app-root').innerHTML = '<h1>app works!</h1>';
18+
`,
19+
'./e2e/app.e2e-spec.ts': `
20+
import { browser, element, by } from 'protractor';
21+
22+
describe('minimal project App', function() {
23+
it('should display message saying app works', () => {
24+
browser.ignoreSynchronization = true;
25+
browser.get('/');
26+
let el = element(by.css('app-root h1')).getText();
27+
expect(el).toEqual('app works!');
28+
});
29+
});
30+
`,
31+
'angular-cli.json': JSON.stringify({
32+
apps: [{
33+
root: 'src',
34+
scripts: ['./script.js']
35+
}],
36+
e2e: { protractor: { config: './protractor.conf.js' } }
37+
}),
38+
}))
39+
.then(() => runServeAndE2e());
1440
}

tests/e2e/tests/test/e2e.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {expectToFail} from '../../utils/utils';
33
import {ngServe} from '../../utils/project';
44

55

6-
function _runServeAndE2e(...args: string[]) {
6+
export function runServeAndE2e(...args: string[]) {
77
return ngServe(...args)
88
.then(() => ng('e2e'))
99
.then(() => killAllProcesses(), (err: any) => {
@@ -16,8 +16,8 @@ export default function() {
1616
// This is supposed to fail without serving first...
1717
return expectToFail(() => ng('e2e'))
1818
// These should work.
19-
.then(() => _runServeAndE2e())
20-
.then(() => _runServeAndE2e('--prod'))
21-
.then(() => _runServeAndE2e('--aot'))
22-
.then(() => _runServeAndE2e('--aot', '--prod'));
19+
.then(() => runServeAndE2e())
20+
.then(() => runServeAndE2e('--prod'))
21+
.then(() => runServeAndE2e('--aot'))
22+
.then(() => runServeAndE2e('--aot', '--prod'));
2323
}

0 commit comments

Comments
 (0)