-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
Added support for image optimiziation with image-webpack-loader #675
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.
Hi @aschempp,
This looks like a nice thing to add, thanks for working on it :)
Also, don't worry about the failing AppVeyor tests, they are not related to your PR.
I finally got around to update this PR. It's pretty much a rewrite of the original implementation, thanks to the suggestions @Lyrkan. I have also update the initial PR description. One caveat is that the signature of the images loaders has changes due to the nature of Webpack and chaining loaders. I'm not sure if this is really a problem, and we could try to keep BC of the signature for as long as Imagemin is not enabled if necessary? |
failing tests don't see related to the PR 🙃 |
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 @aschempp,
Sorry for not reviewing this sooner, I don't think the failing tests are related either.
I've some few comments but that's a great PR :)
One caveat is that the signature of the images loaders has changes due to the nature of Webpack and chaining loaders. I'm not sure if this is really a problem, and we could try to keep BC of the signature for as long as Imagemin is not enabled if necessary?
I would say that's part of Encore's internals and that we shouldn't care too much about BC there... if users are modifying loaders manually they should already know that things could break in a future release (especially when using configureLoaderRule()
since it comes with a warning).
any feedback on this PR? 🙃 |
Sorry for the delay - I have this on my list to check soon - it's something that I think would be super cool :) |
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.
Wow! This is really excellent work - seriously :).
I have one comment on a "decision" you made about disabled. It is the only issue I see with this PR :).
lib/loaders/images.js
Outdated
loaderFeatures.ensurePackagesExistAndAreCorrectVersion('imagemin'); | ||
|
||
const imageminOptions = { | ||
disable: !webpackConfig.isProduction(), |
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.
Hmm, I'm not sure about this. I could see a user enabling this feature while developing, then checking the images and saying "yep! they look ok still!. Then on deploy, their images are now a "lower quality". I think we should just allow the user to control whether or not this is disabled entirely.
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 should just be the default value, and one can just override that in the webpack/encore configuration?
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.
If I call Encore.enableImagemin()
, I would expect that my images would be optimized. NOT optimizing them is unexpected. So I think Encore needs to not have this disable
option at all. Nice and simple: if they call Encore.enableImagemin()
, we enable it. Then, if they choose to, they could decide to disable in dev.
I do realize why you're doing this... it's just too unexpected. One other option would be to add an isEnabled
flag as the first argument to Encore.enableImagemin()
. Then we would document you using it like this:
Encore.enableImagemin(Encore.isProduction());
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.
Sorry for the delay. I decided to remove the disabled-in-dev default. You're probably right that it's unexpected, and it's easy to add. I thought about the additional option as well, but it just adds unnecessary complexity, I can achieve the same using an options object.
Ping! I think we're close - but there is one last big issue :) |
Finally, tests are fixed! Not sure how to fix the frozen yarn file (I'm not using yarn 🙈 ) |
But you should! 😄 The error happens because Here, it's not the case. You've added You need to run |
haha, yeah, that's an opinion 😝
I do basically understand why this happens (I'm familiar with lock files). I'm wondering about the work flow, do I need to rebase on every commit to master to re-generate the lock file? That seems pretty cumbersome, is there a documentation what these tests are for? |
Yes the ideal is to rebase on master, It seems that you already rebased your PR, so just run |
no. That's a fact. The webpack-encore project uses Yarn (Classic) for its dependency management. So when contributing to the project, you need to use it. |
Obviously. I was referring to the 😄 emoji looking more like a general hint 😉
|
What is this waiting for? Anything I (a random developer) can help with? |
This comment has been minimized.
This comment has been minimized.
@Rodrigo001-de awesome non-related spam comment! |
@infabo sorry |
Updated to fix conflicts. Any news on merging this? |
hey @weaverryan it would be great if you could review this, let's merge that nice feature |
hi, anything new, when the feature gets merged? |
Hi, any update on this ? |
Hi, it is planed to fix conflicts and merge this soon? |
Unfortunately, this PR has become unusable due to a lot of changes/improvements in Encore. I guess I can re-implement the feature but I don't like to spend the time if it's not gonna be merged for another year… @weaverryan ? |
That's sad, this feature could be awesome for many people. Currently I manually optimize my images and just copy them into |
This is what I have in all my
|
Thanks a lot @aschempp :) |
Hi! yes, sorry to let this completely get stuck - that’s my fault. Per the last comment from @aschempp, since this is quite conflicted now and enabling it is so straightforward on your app, another option is just to document it. I’m going to close for now. If someone wants to reopen with the updated version - or make a docs PR, that would be great. Again, my apologies @aschempp - you did really nice work here, sometimes it’s hard for me to keep up - sorry :/ |
no hard feelings @weaverryan, one more thing off my plate myself 😆 |
as discussed with @weaverryan here's a first POC for adding image optimization. Looking for general feedback as this is my first time working with Encore, so I'm not sure if my approaches make sense.
The method and feature name are kinda confusing due to the dependencies. We're usingimage-webpack-loader
, which internally usesimagemin
to optimize images. Not sure if stuff should be named after the loader (as of now), or rather something likeenableImageOptimization()
or name the featureimagemin
instead ofimage-webpack
…To enable image optimization, install
image-webpack-loader
and callenableImagemin()
in the Encore config. Further image configuration is available by passing options to the method exactly as inimage-webpack-loader
.#SymfonyHackday