Skip to content

Commit

Permalink
feat(@angular/cli): add publicPath support via command and angular-cl…
Browse files Browse the repository at this point in the history
…i.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
  • Loading branch information
Septimiu Criste authored and filipesilva committed May 4, 2017
1 parent 818936e commit 8c78fb9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/@angular/cli/tasks/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
****************************************************************************************
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/tests/misc/deploy-url.ts
Original file line number Diff line number Diff line change
@@ -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(/<app-root>Loading...<\/app-root>/)) {
throw new Error('Response does not match expected value.');
}
})
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; });
}

0 comments on commit 8c78fb9

Please sign in to comment.