Skip to content

feat(build): add publicPath support via command and angular-cli.json #3285

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
Dec 29, 2016
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
4 changes: 3 additions & 1 deletion packages/angular-cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface BuildOptions {
i18nFile?: string;
i18nFormat?: string;
locale?: string;
deployUrl?: string;
}

const BuildCommand = Command.extend({
Expand Down Expand Up @@ -46,7 +47,8 @@ const BuildCommand = Command.extend({
{ name: 'progress', type: Boolean, default: true },
{ name: 'i18n-file', type: String, default: null },
{ name: 'i18n-format', type: String, default: null },
{ name: 'locale', type: String, default: null }
{ name: 'locale', type: String, default: null },
{ name: 'deploy-url', type: String, default: null, aliases: ['d'] }
],

run: function (commandOptions: BuildOptions) {
Expand Down
1 change: 1 addition & 0 deletions packages/angular-cli/lib/config/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface CliConfig {
root?: string;
outDir?: string;
assets?: string;
deployUrl?: string;
index?: string;
main?: string;
test?: string;
Expand Down
3 changes: 3 additions & 0 deletions packages/angular-cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
],
"default": []
},
"deployUrl": {
"type": "string"
},
"index": {
"type": "string",
"default": "index.html"
Expand Down
3 changes: 2 additions & 1 deletion packages/angular-cli/models/webpack-build-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export function getWebpackCommonConfig(
context: projectRoot,
entry: entryPoints,
output: {
path: path.resolve(projectRoot, appConfig.outDir)
path: path.resolve(projectRoot, appConfig.outDir),
publicPath: appConfig.deployUrl
},
module: {
rules: [
Expand Down
4 changes: 3 additions & 1 deletion packages/angular-cli/models/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ export class NgCliWebpackConfig {
sourcemap = true,
vendorChunk = false,
verbose = false,
progress = true
progress = true,
deployUrl?: string
) {
const config: CliConfig = CliConfig.fromProject();
const appConfig = config.config.apps[0];

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

let baseConfig = getWebpackCommonConfig(
this.ngCliProject.root,
Expand Down
5 changes: 4 additions & 1 deletion packages/angular-cli/tasks/build-webpack-watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default Task.extend({
const project = this.cliProject;

const outputDir = runTaskOptions.outputPath || CliConfig.fromProject().config.apps[0].outDir;
const deployUrl = runTaskOptions.deployUrl ||
CliConfig.fromProject().config.apps[0].deployUrl;
rimraf.sync(path.resolve(project.root, outputDir));

const config = new NgCliWebpackConfig(
Expand All @@ -30,7 +32,8 @@ export default Task.extend({
runTaskOptions.sourcemap,
runTaskOptions.vendorChunk,
runTaskOptions.verbose,
runTaskOptions.progress
runTaskOptions.progress,
deployUrl
).config;
const webpackCompiler: any = webpack(config);

Expand Down
5 changes: 4 additions & 1 deletion packages/angular-cli/tasks/build-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default <any>Task.extend({
const project = this.cliProject;

const outputDir = runTaskOptions.outputPath || CliConfig.fromProject().config.apps[0].outDir;
const deployUrl = runTaskOptions.deployUrl ||
CliConfig.fromProject().config.apps[0].deployUrl;
rimraf.sync(path.resolve(project.root, outputDir));
const config = new NgCliWebpackConfig(
project,
Expand All @@ -31,7 +33,8 @@ export default <any>Task.extend({
runTaskOptions.sourcemap,
runTaskOptions.vendorChunk,
runTaskOptions.verbose,
runTaskOptions.progress
runTaskOptions.progress,
deployUrl
).config;

const webpackCompiler: any = webpack(config);
Expand Down
15 changes: 15 additions & 0 deletions tests/e2e/tests/build/deploy-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {ng} from '../../utils/process';
import {expectFileToMatch} from '../../utils/fs';
import {updateJsonFile} from '../../utils/project';


export default function() {
return ng('build', '-d', 'deployUrl/')
.then(() => expectFileToMatch('dist/index.html', 'deployUrl/main.bundle.js'))
.then(() => updateJsonFile('angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['deployUrl'] = 'config-deployUrl/';
}))
.then(() => ng('build'))
.then(() => expectFileToMatch('dist/index.html', 'config-deployUrl/main.bundle.js'));
}