From 8c78fb98efaea44c42e389c0d9060df214923684 Mon Sep 17 00:00:00 2001 From: Septimiu Criste Date: Fri, 28 Apr 2017 00:23:01 +0300 Subject: [PATCH] feat(@angular/cli): add publicPath support via command and angular-cli.json for webpack-dev-server This adds support for publicPath to webpack-dev-server via ng serve The server would have to be started like ng serve --deploy-url /deploypath --base-href /deploypath. The app will be served from http://localhost:4200/deploypath Should fix #2727 --- packages/@angular/cli/tasks/serve.ts | 5 +++++ tests/e2e/tests/misc/deploy-url.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/e2e/tests/misc/deploy-url.ts diff --git a/packages/@angular/cli/tasks/serve.ts b/packages/@angular/cli/tasks/serve.ts index c91200a07a6d..a7d1c7bdacac 100644 --- a/packages/@angular/cli/tasks/serve.ts +++ b/packages/@angular/cli/tasks/serve.ts @@ -161,6 +161,11 @@ export default Task.extend({ webpackDevServerConfiguration.hot = serveTaskOptions.hmr; + // set publicPath property to be sent on webpack server config + if (serveTaskOptions.deployUrl) { + webpackDevServerConfiguration.publicPath = serveTaskOptions.deployUrl; + } + if (serveTaskOptions.target === 'production') { ui.writeLine(chalk.red(stripIndents` **************************************************************************************** diff --git a/tests/e2e/tests/misc/deploy-url.ts b/tests/e2e/tests/misc/deploy-url.ts new file mode 100644 index 000000000000..b43672e0eb84 --- /dev/null +++ b/tests/e2e/tests/misc/deploy-url.ts @@ -0,0 +1,18 @@ +import { killAllProcesses } from '../../utils/process'; +import { request } from '../../utils/http'; +import { expectToFail } from '../../utils/utils'; +import { ngServe } from '../../utils/project'; + +export default function () { + return Promise.resolve() + // check when setup through command line arguments + .then(() => ngServe('--deploy-url', '/deployurl', '--base-href', '/deployurl')) + .then(() => expectToFail(() => request('http://localhost:4200'))) + .then(() => request('http://localhost:4200/deployurl')) + .then(body => { + if (!body.match(/Loading...<\/app-root>/)) { + throw new Error('Response does not match expected value.'); + } + }) + .then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }); +}