Skip to content

refactor(server): move publicPath configuration from CLI to API #2098

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

Closed
Closed
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
3 changes: 3 additions & 0 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const createDomain = require('./utils/createDomain');
const runBonjour = require('./utils/runBonjour');
const routes = require('./utils/routes');
const getSocketServerImplementation = require('./utils/getSocketServerImplementation');
const setPublicPath = require('./utils/setPublicPath');
const schema = require('./options.json');

// Workaround for node ^8.6.0, ^9.0.0
Expand All @@ -58,6 +59,8 @@ class Server {
this.compiler = compiler;
this.options = options;

setPublicPath(compiler, options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this in updateCompiler

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilebottnawi this is not altering the compiler at all though, only using the compiler's option data to set devServer.publicPath. But if you still think it should be there I have no strong opinion.


// Setup default value
this.options.contentBase =
this.options.contentBase !== undefined
Expand Down
13 changes: 0 additions & 13 deletions lib/utils/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@ function createConfig(config, argv, { port }) {
options.overlay = argv.overlay;
}

if (!options.publicPath) {
// eslint-disable-next-line
options.publicPath =
(firstWpOpt.output && firstWpOpt.output.publicPath) || '';

if (
!isAbsoluteUrl(String(options.publicPath)) &&
options.publicPath[0] !== '/'
) {
options.publicPath = `/${options.publicPath}`;
}
}

if (!options.filename && firstWpOpt.output && firstWpOpt.output.filename) {
options.filename = firstWpOpt.output && firstWpOpt.output.filename;
}
Expand Down
24 changes: 24 additions & 0 deletions lib/utils/setPublicPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const isAbsoluteUrl = require('is-absolute-url');

function setPublicPath(compiler, options) {
const firstWpOpt = compiler.compilers
? compiler.compilers[0].options
: compiler.options;

if (!options.publicPath) {
// eslint-disable-next-line
options.publicPath =
(firstWpOpt.output && firstWpOpt.output.publicPath) || '';

if (
!isAbsoluteUrl(String(options.publicPath)) &&
options.publicPath[0] !== '/'
) {
options.publicPath = `/${options.publicPath}`;
}
}
}

module.exports = setPublicPath;