Skip to content

Replace error throwing with logger warning when publicPath is not absolute #196

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 4 commits into from
Jan 30, 2018
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
6 changes: 3 additions & 3 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ class WebpackConfig {
setPublicPath(publicPath) {
if (publicPath.includes('://') === false && publicPath.indexOf('/') !== 0) {
// technically, not starting with "/" is legal, but not
// what you want in most cases. Let's not let the user make
// a mistake (and we can always change this later).
throw new Error('The value passed to setPublicPath() must start with "/" or be a full URL (http://...)');
// what you want in most cases. Let's warn the user that
// they might be making a mistake.
logger.warning('The value passed to setPublicPath() should *usually* start with "/" or be a full URL (http://...). If you\'re not sure, then you should probably change your public path and make this message disappear.');
}

// guarantee a single trailing slash
Expand Down
7 changes: 3 additions & 4 deletions test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,11 @@ describe('WebpackConfig object', () => {
expect(config.publicPath).to.equal('https://example.com/');
});

it('foo/ throws an exception', () => {
it('You can omit the opening slash, but get a warning', () => {
const config = createConfig();
config.setPublicPath('foo');

expect(() => {
config.setPublicPath('foo/');
}).to.throw('The value passed to setPublicPath() must start with "/"');
expect(logger.getMessages().warning).to.have.lengthOf(1);
});
});

Expand Down