You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #96 Relaxed public path requirements with dev-server (robertfausk, weaverryan)
This PR was merged into the master branch.
Discussion
----------
Relaxed public path requirements with dev-server
Fixes#59 and finishes #66.
* Adds a new `--keep-public-path` option for `dev-server`. When used, your `publicPath` is not prefixed with the dev server URL. For #59, this means you can use `setPublicPath('/build')` with the dev-server, and your assets will remain local (i.e. `/build/main.js` instead of `http://localhost:8080/build/main.js`).
* It is now possible to pass an absolute URL to `setPublicPath()` without an error when using `dev-server`. But, we issue a big warning, because this means your assets will point to to that absolute URL, instead of to the dev-server (which for most setups, is not what you want).
@samjarrett I'd love to confirm that this would solve your issue in Docker :).
Commits
-------
4bc1e19 Using real public path, though it doesn't look like it matters
92e22af Allowing an absolute publicPath with dev-server, but showing a warning
830fdb5 Adding --keep-public-path to dev-server to allow you to fully control the publicPath
b27f7c9 Reversing some of the changes we won't do for now, and adding the failing test
e206a12 fix issue in generated public path of manifest.json
eb5565b convert error into warning
910b6bc convert error into warning
Copy file name to clipboardExpand all lines: lib/WebpackConfig.js
+17-22
Original file line number
Diff line number
Diff line change
@@ -86,23 +86,11 @@ class WebpackConfig {
86
86
}
87
87
88
88
setPublicPath(publicPath){
89
-
/*
90
-
* Do not allow absolute URLs *and* the webpackDevServer
91
-
* to be used at the same time. The webpackDevServer basically
92
-
* provides the publicPath (and so in those cases, publicPath)
93
-
* is simply used as the default manifestKeyPrefix.
94
-
*/
95
-
if(publicPath.includes('://')){
96
-
if(this.useDevServer()){
97
-
thrownewError('You cannot pass an absolute URL to setPublicPath() and use the dev-server at the same time. Try using Encore.isProduction() to only configure your absolute publicPath for production.');
98
-
}
99
-
}else{
100
-
if(publicPath.indexOf('/')!==0){
101
-
// technically, not starting with "/" is legal, but not
102
-
// what you want in most cases. Let's not let the user make
103
-
// a mistake (and we can always change this later).
104
-
thrownewError('The value passed to setPublicPath() must start with "/" or be a full URL (http://...)');
logger.warning(`Passing an absolute URL to setPublicPath() *and* using the dev-server can cause issues. Your assets will load from the publicPath (${this.webpackConfig.publicPath}) instead of from the dev server URL (${this.webpackConfig.runtimeConfig.devServerUrl}).`);
0 commit comments