Skip to content

fix(build): fix path error when appConfig has no main #3867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/angular-cli/models/webpack-build-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ export function getWebpackCommonConfig(
) {

const appRoot = path.resolve(projectRoot, appConfig.root);
const appMain = path.resolve(appRoot, appConfig.main);
const nodeModules = path.resolve(projectRoot, 'node_modules');

let extraPlugins: any[] = [];
let extraRules: any[] = [];
let lazyChunks: string[] = [];

let entryPoints: { [key: string]: string[] } = {
main: [appMain]
};
let entryPoints: { [key: string]: string[] } = {};

if (appConfig.main) {
entryPoints['main'] = [path.resolve(appRoot, appConfig.main)];
}

// determine hashing format
const hashFormat = getOutputHashFormat(outputHashing);
Expand Down
34 changes: 17 additions & 17 deletions packages/angular-cli/models/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export class NgCliWebpackConfig {
deployUrl?: string,
outputHashing?: string
) {
const config: CliConfig = CliConfig.fromProject();
const appConfig = config.config.apps[0];
const appConfig = CliConfig.fromProject().config.apps[0];
const projectRoot = this.ngCliProject.root;

appConfig.outDir = outputDir || appConfig.outDir;
appConfig.deployUrl = deployUrl || appConfig.deployUrl;

let baseConfig = getWebpackCommonConfig(
this.ngCliProject.root,
projectRoot,
environment,
appConfig,
baseHref,
Expand All @@ -52,28 +52,28 @@ export class NgCliWebpackConfig {
progress,
outputHashing
);
let targetConfigPartial = this.getTargetConfig(
this.ngCliProject.root, appConfig, sourcemap, verbose
);
const typescriptConfigPartial = isAoT
? getWebpackAotConfigPartial(this.ngCliProject.root, appConfig, i18nFile, i18nFormat, locale)
: getWebpackNonAotConfigPartial(this.ngCliProject.root, appConfig);
let targetConfigPartial = this.getTargetConfig(projectRoot, appConfig, sourcemap, verbose);

if (appConfig.mobile) {
let mobileConfigPartial = getWebpackMobileConfigPartial(this.ngCliProject.root, appConfig);
let mobileProdConfigPartial = getWebpackMobileProdConfigPartial(this.ngCliProject.root,
appConfig);
let mobileConfigPartial = getWebpackMobileConfigPartial(projectRoot, appConfig);
let mobileProdConfigPartial = getWebpackMobileProdConfigPartial(projectRoot, appConfig);
baseConfig = webpackMerge(baseConfig, mobileConfigPartial);
if (this.target == 'production') {
targetConfigPartial = webpackMerge(targetConfigPartial, mobileProdConfigPartial);
}
}

this.config = webpackMerge(
baseConfig,
targetConfigPartial,
typescriptConfigPartial
);
let config = webpackMerge(baseConfig, targetConfigPartial);

if (appConfig.main) {
const typescriptConfigPartial = isAoT
? getWebpackAotConfigPartial(projectRoot, appConfig, i18nFile, i18nFormat, locale)
: getWebpackNonAotConfigPartial(projectRoot, appConfig);

config = webpackMerge(config, typescriptConfigPartial);
}

this.config = config;
}

getTargetConfig(projectRoot: string, appConfig: any, sourcemap: boolean, verbose: boolean): any {
Expand Down
1 change: 1 addition & 0 deletions packages/angular-cli/tasks/serve-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default Task.extend({
entryPoints.push('webpack/hot/dev-server');
config.plugins.push(new webpack.HotModuleReplacementPlugin());
}
if (!config.entry.main) { config.entry.main = []; }
config.entry.main.unshift(...entryPoints);
webpackCompiler = webpack(config);

Expand Down
34 changes: 30 additions & 4 deletions tests/e2e/tests/misc/minimal-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { writeFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { writeFile, writeMultipleFiles } from '../../utils/fs';
import { runServeAndE2e } from '../test/e2e';


export default function () {
Expand All @@ -8,7 +8,33 @@ export default function () {
apps: [{
root: 'src',
main: 'main.ts'
}]
}],
e2e: { protractor: { config: './protractor.conf.js' } }
})))
.then(() => ng('build'));
.then(() => runServeAndE2e())
.then(() => writeMultipleFiles({
'./src/script.js': `
document.querySelector('app-root').innerHTML = '<h1>app works!</h1>';
`,
'./e2e/app.e2e-spec.ts': `
import { browser, element, by } from 'protractor';

describe('minimal project App', function() {
it('should display message saying app works', () => {
browser.ignoreSynchronization = true;
browser.get('/');
let el = element(by.css('app-root h1')).getText();
expect(el).toEqual('app works!');
});
});
`,
'angular-cli.json': JSON.stringify({
apps: [{
root: 'src',
scripts: ['./script.js']
}],
e2e: { protractor: { config: './protractor.conf.js' } }
}),
}))
.then(() => runServeAndE2e());
}
10 changes: 5 additions & 5 deletions tests/e2e/tests/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {expectToFail} from '../../utils/utils';
import {ngServe} from '../../utils/project';


function _runServeAndE2e(...args: string[]) {
export function runServeAndE2e(...args: string[]) {
return ngServe(...args)
.then(() => ng('e2e'))
.then(() => killAllProcesses(), (err: any) => {
Expand All @@ -16,8 +16,8 @@ export default function() {
// This is supposed to fail without serving first...
return expectToFail(() => ng('e2e'))
// These should work.
.then(() => _runServeAndE2e())
.then(() => _runServeAndE2e('--prod'))
.then(() => _runServeAndE2e('--aot'))
.then(() => _runServeAndE2e('--aot', '--prod'));
.then(() => runServeAndE2e())
.then(() => runServeAndE2e('--prod'))
.then(() => runServeAndE2e('--aot'))
.then(() => runServeAndE2e('--aot', '--prod'));
}