feat(@angular/cli): add baseHref property to appConfig

This commit is contained in:
laco0416 2017-06-08 10:30:20 +09:00 committed by Mike Brocchi
parent 01cbf65728
commit 692b378770
3 changed files with 14 additions and 2 deletions

View File

@ -79,6 +79,10 @@
"type": "string", "type": "string",
"description": "URL where files will be deployed." "description": "URL where files will be deployed."
}, },
"baseHref": {
"type": "string",
"description": "Base url for the application being built."
},
"index": { "index": {
"type": "string", "type": "string",
"default": "index.html", "default": "index.html",

View File

@ -97,7 +97,8 @@ export class NgCliWebpackConfig {
public mergeConfigs(buildOptions: BuildOptions, appConfig: any) { public mergeConfigs(buildOptions: BuildOptions, appConfig: any) {
const mergeableOptions = { const mergeableOptions = {
outputPath: appConfig.outDir, outputPath: appConfig.outDir,
deployUrl: appConfig.deployUrl deployUrl: appConfig.deployUrl,
baseHref: appConfig.baseHref
}; };
return Object.assign({}, mergeableOptions, buildOptions); return Object.assign({}, mergeableOptions, buildOptions);

View File

@ -1,6 +1,7 @@
import {ng} from '../../utils/process'; import {ng} from '../../utils/process';
import {expectFileToMatch} from '../../utils/fs'; import {expectFileToMatch} from '../../utils/fs';
import {getGlobalVariable} from '../../utils/env'; import {getGlobalVariable} from '../../utils/env';
import {updateJsonFile} from '../../utils/project';
export default function() { export default function() {
@ -10,5 +11,11 @@ export default function() {
} }
return ng('build', '--base-href', '/myUrl') return ng('build', '--base-href', '/myUrl')
.then(() => expectFileToMatch('dist/index.html', /<base href="\/myUrl">/)); .then(() => expectFileToMatch('dist/index.html', /<base href="\/myUrl">/))
.then(() => updateJsonFile('.angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['baseHref'] = '/myUrl';
}))
.then(() => ng('build'))
.then(() => expectFileToMatch('dist/index.html', /<base href="\/myUrl">/))
} }