-
-
Notifications
You must be signed in to change notification settings - Fork 256
Dynamic public path #334
Dynamic public path #334
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is breaking change and invalid usage.
- Why breaking change?
Other developers can use __webpack_public_path__
in source code for rewriting public path so they get __webpack_public_path__ + __webpack_public_path__ + publicPathToAsset
and it is break their apps.
- Why it is invalid and how valid?
https://webpack.js.org/guides/public-path/#on-the-fly
Other solution?
Yes, use hook to rewrite path in webpack. Unfortunately it is break very many apps and we can't merge this, also webpack@5 will be has built-in asset loader (i.e. file-loader) and you need to use hook for changing this. So i strongly recommend rewrite you plugin on using hook(s). Thanks
That‘s too bad, and I don‘t completely understand it. Could it be that there is a misunderstanding on what the PR does?
|
hm, why don't use |
That is not possible, because the function is executed at buildtime, but I need to modify the publicPath at runtime depending on runtime environment variables that cannot be present at buildtime. |
Please provide plugin/app/reproducible repo with problematic and describe what you want to solve in README.md. As i said above webpack@5 will have built-in file-loader so you solution can't work in next webpack version, we should search way how to solve this in other way. |
oh, looks i see your problem, no need link |
Ok thx |
Let's keep open |
I think we need do breaking change again to solve this,
Good catch, anyway
|
Thanks for taking the time to understand the problem! Until I can switch to webpack 5 it‘s fine for me to use my forked package. |
I think we should correct this behavior and migrate all tests to webpack@5 to ensure all works es expected |
Not true because there is not
Also not true because there is no
No, this does not work, because of the |
Do you try this? We don't add anything when Line 34 in 903aa75
It is hack to solve problem what i describe above and we need fix it as bug with major release |
Not true. Line 44 is also executed in this case afterwards, because there is no |
Oh, yes sorry, anyway you catch the bug and we fix it in next release (workaround: use forked repo right now) |
/cc @fabb sorry for delay, let's use better name (ideas?), also let's do this as |
Sorry, no better ideas for naming 🙈 String|Function is a good idea, i guess you mean for the |
Maybe just |
Ah, good idea. I just saw that |
Feel free to ping me |
@evilebottnawi I've implemented the change. I fear it might be a bit confusing for users on how to use the option correctly. Please take a look at the unit tests and tell me what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need add doc about this option and add description
to schema
Good work, thanks!
ok done! any additional remarks? should we add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
@fabb let's rebase |
a38391f
to
0c84e34
Compare
when the option is active, and a publicPath is set, it will prefix the provided publicPath with the dynamic __webpack_public_path__
added unit tests for option "prefixPublicPathWithWebpackPublicPath"
removed prefixPublicPathWithWebpackPublicPath and introduced postTransformPublicPath option instead
0c84e34
to
64f2eb6
Compare
done! |
Good work! |
}, | ||
}; | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, i forgot, let's add Example use case for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i pushed an example, is this what you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, i see, just think about additional section in Example
in README
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ups, i forgot to push the commit i was talking about 😅
i meant this one: 460127d
README.md
Outdated
@@ -603,6 +603,72 @@ Result: | |||
path/to/file.png?e43b20c069c4a01867c31e98cbce33c9 | |||
``` | |||
|
|||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use heading here instead ---
, something like ### Dynamic public path with __webpack_public_path__
(maybe better name for heading)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i added a little paragraph for explaining the use case. makes sense?
@evilebottnawi can we merge the PR? |
@fabb yep, at this week we merge and release, in my todo |
I remember you was against it, @evilebottnawi? Quotes are yours:
Does this PR fix this on webpack side? Where's the "minimum reproducible test repo"?
You refused to merge my PR even if it was not adding any new options, but merged this one with an additional option? |
@prontiol A similar feature was implemented on webpack side and several people requested a similar solution for file-loader. Sometimes I'm mistaken, I should have heard you better, sometimes it’s difficult because of the influx of many ideas, most of which look terrible, sorry |
This PR contains a:
Motivation / Use-Case
We use the
file-loader
in a next.js plugin to automatically generate asset urls by importing the assets. The asset file names will be hashed, which is good for caching indefinitely. The plugin supports next.js'assetPrefix
which allows to provide a different cache server host url for static assets. Next.js uses__webpack_public_path__
by default.The problem is that in our case the
assetPrefix
is dynamic at runtime, and will be set based on environment variables which are not present at compile time. The plugin-static gets used during compile time though, and will only use theassetPrefix
that is based on environment variables present at compile time. The proper way around this is to make use of__webpack_public_path__
. The problem withfile-loader
is that when setting thepublicPath
, it is not possible to use the__webpack_public_path__
. Therefore a new setting is needed which allows to prefix with__webpack_public_path__
.Breaking Changes
No breaking changes.
Additional Info