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
Fix browser bundling with webpack 5 #1553
Conversation
I think that the browser field is missing `url: false`. I'm not completely sure that this is the right fix and also the npm package `url` does not implement the APIs used by postcss. steps to reproduce ``` mkdir postcss-browser cd postcss-browser mkdir src echo 'import "postcss";' > src/index.js npm init -y npm install webpack webpack-cli postcss npx webpack ``` This will emit error: ``` ERROR in ./node_modules/postcss/lib/input.js 3:39-53 Module not found: Error: Can't resolve 'url' in 'C:\projects\postcss-web-bundle\postcss-browser\node_modules\postcss\lib' ```
Can I ask you to test this branch in webpack 4 and webpack 5? |
I didn't. I will do later today. But I guess that any way the webpack 4 built-in polyfill is also wrong since it's based on the same url polyfill. |
|
True (it will throw an error for the missing function). No one today that uses postcss in the browser have those functions available for them (unless there is a polyfill I don't know about). I truly consider to create a proper polyfill for them but up until now there isn't any. |
It will be breaking changes |
Because we will break webpack 4 build. We need a solution to support both bundlers without config changes (or with some migration help). |
At the current state of things:
I propose one of two possible solutions:
Assuming the above is correct, either approach will probably not be a breaking change, but a bugfix. |
I like the idea |
After deep investigation I notice few things: Source map generation is disabled when bundling for browser since path is mapped to false (this is why it didn't break) Line 280 in 8682b1e
And the other two locations that uses url are not really that important
I did managed to create the polyfill but I'm now thinking maybe disable these features will be good also. If not maybe we should consider to also to implement the path behavior required for the entire code to work. (path.resolve is already in-lined inside my url polyfill) Anyhow I will probably update the PR tomorrow. |
Yeap, disabling this features will be the better option. |
It turned out more "complex" for me to remove these features because I wasn't sure how to handle the error cases. Should I add |
Yeap |
Co-authored-by: Andrey Sitnik <andrey@sitnik.ru>
Looks good. Thanks. I will release it next week since I need to take deal with another issue. |
Thanks. |
Do you have Twitter to mention you in the release tweet? |
No Twitter 10x. |
I think that the browser field is missing
url: false
.I'm not completely sure that this is the right fix and also the npm package
url
does not implement the APIs used by postcss.steps to reproduce
This will emit error: