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
Update to webpack v5 #4054
Update to webpack v5 #4054
Conversation
Also: is there a reason you removed the |
Good catch - wasn't aware of that.
Not sure anymore - isn't it default to |
@cw789 you're right, parallel is true by default now |
I have set this up locally and can confirm it woks. And I upgraded a legacy project. @chrismccord @josevalim |
Thank you @cw789! I removed the stats stuff because this is something we discussed in the past and we should probably have a separate discussion before moving forward. This looks good to be merged to me. By the time Phoenix v1.6 is out, webpack will probably be more stable and some plugins will have caught up. |
Thanks everyone for reviewing. I'm totally fine by removing the stats stuff within this PR. Maybe it's not bad to show people what's going on. By the way I also would like the same version syntax |
Live reloading seems to be broken after these changes. Might be my something in my config, but thought I'll let you know just in case. |
This is an issue for for me as well. Live reload is triggering an event for every file copied into /priv/static. Previously, it would only trigger an event for the changed file. I have quite a few images and each time I change a js file, this is what I see in the logs:
The browser is trying to refresh for each of those events. Could this be an issue webpack's copy plugin? I assume it shouldn't be copying files that haven't changed. |
Indeed this doesn't look like I would expect it to be too. For now I have no solution. |
🤔 Interesting, I've not experienced this in my project so far but then I don't have a huge number of things in |
I think webpack-cli 5.x isn't watching stdin any more so SIGINT signal do not close node process. The param After phoenix server closed, check I use a small
|
@vortizhe That's the issue I'm seeing. Thanks! |
webpack/webpack-cli#885 seems related to this issue? This was reported way before v5 release though (May 2019) so I wonder what's changed in v5 to make this noticeable for you folks if they are related. |
So I again invested bit of time in this. I only see livereload beeing triggered twice every time.
But I don't know if this behavior was the same before. So from my side, this is ready to be merged. |
Hopefully my last changes:
|
Are we going foreward with this (webpack v5)? Background: If webpack means to much maintenance trouble it's probably the better way to slim down JS things (webpack?, Sass?, ...). Snowpack seems promising: |
@cw789 the plan is to go ahead with this but we need to balance between pushing to Webpack 5 too soon and that leading to frustration because the ecosystem did not catch up yet. I assume that, by the time we release a new Phoenix version, this will be safe, otherwise we will go with #4146. :) If there is anything broken right now - not warnings but literally something does not work - then we should do the smallest PR possible to fix it and backport to the v1.5 branch. Otherwise these changes go to v1.6. :) |
@cw789 as José said please let us know what issues you are having on the current setup. I just built a fresh 1.5 app and webpack has no problems. |
Phoenix 1.5.7 wont work with Node.js v15. @chrismccord Can you approve you've used Node.js ≤ v14? I've not reproduced this issue, but seems so from reports in an issue & Elixir forum. So the smallest PR is mentioning it will only work with Node.js ≤ v14 ... |
Sidebar, I actually plan on removing node-sass so that is perhaps the fastest way to fix this for all users? |
Note:
|
node-sass wouldn't be removed until 1.6, but the fact other folks might be having issues with webpack/node/et al is not new, so we need to tread carefully. I'm still seeing vast majority of folks have no issues on the current setup. Historically the js build tool ecosystem has been fragile, so moving to this PR is not guaranteed to be a panacea. We may cause as many issues as we solve for people, so we need to be sure that webpack v5 is golden across OS's, node versions, major packages, etc. To be clear, we will be moving to webpack v5 as soon as makes sense, but I hope this gives insight into the slow roll to get there. |
Thanks Chris. I understand the rollout tempo & totally agree. & all that is not a critic. It's the cause why I came across to Elixir. |
Just tested this with node v15 and it does indeed work and fixes the current broken state of the new project. Thought definitely agree, I'm sure this would break something new for someone soon, so not too bullish either way (as new projects work fine with node v14) |
I've been testing this for the last few days and it's been working okay, but I haven't gone too deep with it yet. (v14 less desirable for me as I'm on darwin/arm64 and afaik there's no native build for v14 there yet, only v15.) |
It would be good to change the minimum required Node.js version in the docs, which currently state:
https://github.com/phoenixframework/phoenix/blob/master/guides/introduction/installation.md |
Thanks a lot to everyone involved. I hope there are simpler solutions coming our way. Maybe snowpack. Meanwhile, I had to set
in
in
and the image itself is located at my webpack config
|
In case anyone is following along with these changes in their own project — and also as an FYI for the author and maintainers — I ran into an issue where the Original issue:
Note this only happened after I upgraded At the end of the day, the changes I made are: - "css-minimizer-webpack-plugin": "^1.x",
+ "css-minimizer-webpack-plugin": "^2.x",
+ "glob": "^7.1.6", Thank you all for your contributions and thoughtfulness. |
publicPath: '/js/' | ||
}, | ||
devtool: devMode ? 'eval-cheap-module-source-map' : undefined, | ||
module: { | ||
rules: [ | ||
{ |
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.
Hey so I did my own webpack upgrade and I think you'll need a few other rules to ensure the most compatibility:
{
test: /\.svg$/i,
type: 'asset/inline'
},
{
test: /\.(png|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
This comes directly from the Webpack 5 tutorial to ensure fonts and images are loaded successfully as well
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 also noticed once that this is needed if you want to process assets by webpack.
But then I didn't touch any of these anymore.
It was not clear for me which file types people really need to have in here.
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.
makes sense - i think it's pretty safe to say that in general css, js, images, and fonts are all fair game
'...', | ||
new CssMinimizerPlugin() | ||
] | ||
}, |
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 also think you will get compilation errors if you don't specify target: 'nodeX.Y',
because the default option for target
is web
which will usually cause things like http
and url
to blow up upon upgrading. Since these assets are built in a node-like environment targeting Node over web will ensure Webpack successfully compiles.
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.
That's a thing I for myself would need to explore more in detail. I didn't get the consequences of this now.
For Phoenix deploys the target
in my opinion should be web
- not node
.
But you might be right.
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 thought the same too but when I deployed with web
I was getting errors around url
and http
and you'd have to set resolutions that resolve to false
for both. Since this is a node
environment for how we build our assets if you change it to node
everything will resolve and pass.
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 did my own Webpack 5 upgrade and the only way to get all compilation errors to disappear was to implement a few additional changes on top of yours
Thanks @acconrad for your review. To all: When someone tell me for sure this will get relevance for Phoenix again, of course I could have a fresh look. |
@cw789 I'm happy to take this over! You can either close this out and I can resume it in my own branch or I can just take this over from this open PR? @josevalim @chrismccord any recommendations? I have a version of this working perfectly with no compiler errors or warnings from webpack. |
It breaks also with node 16, which is the default version if you install via homebrew, which is quite common for OS X users. I think it should at least be mentioned in the getting started guide, it's quite frustrating to follow a list of instructions and see they don't work, it doesn't give a good 'first impression' to newcomers. |
@cw789 if you close this PR I'll open one with the corrected points |
with webpack 5 we have to give both
|
Dear maintainers. I'm in favour in closing this PR - please feel free. PS: This PR is anyway outdated now. In need of a revisit. |
Revision
Background "source-map":
Terser plugin doesn't work with "eval-cheap-module-source-map".
Suggestion for additional PR (if it will improve build time):
Initial
Including update to webpack 5.
Some things are probably opinionated.
Edit:
optimize-css-assets-webpack-plugin
withcss-minimizer-webpack-plugin
(Thx @optikfluffel)source-map
instead ofeval-cheap-source-map
Has open Issue (warning in CLI, but seem to work anyway): webpack/webpack-cli#1918Concerns discussion: https://elixirforum.com/t/upgrade-to-webpack-5/35010
Resolve #4020