Skip to content

Commit 8c78fb9

Browse files
Septimiu Cristefilipesilva
Septimiu Criste
authored andcommitted
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
1 parent 818936e commit 8c78fb9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/@angular/cli/tasks/serve.ts

+5
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ export default Task.extend({
161161

162162
webpackDevServerConfiguration.hot = serveTaskOptions.hmr;
163163

164+
// set publicPath property to be sent on webpack server config
165+
if (serveTaskOptions.deployUrl) {
166+
webpackDevServerConfiguration.publicPath = serveTaskOptions.deployUrl;
167+
}
168+
164169
if (serveTaskOptions.target === 'production') {
165170
ui.writeLine(chalk.red(stripIndents`
166171
****************************************************************************************

tests/e2e/tests/misc/deploy-url.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { killAllProcesses } from '../../utils/process';
2+
import { request } from '../../utils/http';
3+
import { expectToFail } from '../../utils/utils';
4+
import { ngServe } from '../../utils/project';
5+
6+
export default function () {
7+
return Promise.resolve()
8+
// check when setup through command line arguments
9+
.then(() => ngServe('--deploy-url', '/deployurl', '--base-href', '/deployurl'))
10+
.then(() => expectToFail(() => request('http://localhost:4200')))
11+
.then(() => request('http://localhost:4200/deployurl'))
12+
.then(body => {
13+
if (!body.match(/<app-root>Loading...<\/app-root>/)) {
14+
throw new Error('Response does not match expected value.');
15+
}
16+
})
17+
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; });
18+
}

0 commit comments

Comments
 (0)