-
-
Notifications
You must be signed in to change notification settings - Fork 200
Allow to disable the default image and font loaders #103
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
Conversation
Thanks @Lyrkan! I thought your suggestion here: #73 (comment) was interesting:
I did think this would be an issue at first, but I think I'm wrong (other than the possible edge case of the Later you said:
What made you think this? What else would you want to change on the font/image loaders? If there's something beyond fixing this path issue, we could also add code to make these settings on these loaders configurable. I'm not -1 on this PR - but I want to understand the full picture so we offer the best solution. Cheers! |
Hi Ryan, I changed my mind about the first suggestion because it'll only cover one specific thing amongst many others that the users may need. Here are some of them off the top of my head:
Covering all these cases one by one would need a lot of new methods and may not be worth it since there already is WDYT? |
c9aaf20
to
0bbf35b
Compare
Yo @Lyrkan! Hmm. First, let's strictly solve #73... which I think means (A) we always add
About this PR specifically:
On the last 2 points, I'm not trying to totally disagree with you :). More, I'm playing devil's advocate: if we're going to make a change, I really want us to understand what real-world problems people are having. I agree with your points... but they're soft - they sounds like possibilities of what users might need - but not coming from real scenarios. Thanks for the convo on this! It's very helpful! |
Hey Ryan, I entirely agree with you about the fact that this PR doesn't solve #73 on its own and that something else should be done to the default behavior. I wouldn't mind creating another PR for that if we can settle on a way to do it. I'm not sure about adding the About using Initial configDirectory structure:
webpack.config.js: Encore
.setOutputPath('web/build/')
.setPublicPath('/build')
.cleanupOutputBeforeBuild()
.addStyleEntry('test1', './assets/css/test1.scss')
.addStyleEntry('test2', './assets/css/subdirectory/test2.scss')
.enableSassLoader()
; test1.scss: .test1-1 {
background-image: url('../images/image.jpeg');
}
.test1-2 {
background-image: url('../../images/image.jpeg');
}
.test1-3 {
background-image: url('../../node_modules/vendor1/images/image.jpeg');
}
.test1-4 {
background-image: url('../../node_modules/../assets/images/image.jpeg');
} test2.scss: .test2-1 {
background-image: url('../../images/image.jpeg');
}
.test2-2 {
background-image: url('../../../node_modules/vendor1/images/image.jpeg');
} Using the current default settings 😢
Using
|
Wow :). You're research into the [path] is great!!! I can't think of any practical issues with [path] now that I see it. But, it seems like a heavy solution to solve the edge case of duplicate filenames - the directories get way bigger, node_modules is exposed as a directory name potentially (not a real problem, but odd). Especially when there is already a workaround (enabling versioning). You mention that people might want to version themselves - e.g. with a query parameter. That's totally true... but, you shouldn't rely on these paths from outside of webpack. If you're referencing the images in CSS, you don't care about the final path. And if you need to reference an image from outside of webpack (e.g. Just in an img tag), you should use a copy plugin to move the asset to a known directory (if you don't also reference that image from CSS, you will need a copy plugin to put it into the build dir). That copy ability is a todo still... I admit :)... but it will get done. So in this moment, I think the proper way to fix this is by enabling versioning: either we always include [hash] in the filename, or (if possible) we detect when we have an image collision and print a warning that the user needs to enable versioning to fix the problem. I'm lit of time to reply to the second part of your message. Apologies - I want to give it roper attention! |
Hey, I find a few more minutes. I'm flying today, so working in short sprints! Zoom!
Definitely don't want a frustrating experience :). So So, I think adding the 2 methods for removing the 2 loaders is fine. There are only 4 loaders (the other 2 being .js and .css) that are forced on you... so allowing these to be removed, seems ok. But, it seems like most of your use-cases can be solved by allowing the user to extend the configuration for the loaders. An extension point (e.g. to add Cheers! |
Hi Ryan,
Yep, that's what I meant by "ugly paths" in #73 :)
True, same thing if you
I guess you're right there too. Not sure about the copy as a recommended way to do that though, it would probably be easier for people to directly put this kind of images somewhere in their public folder. But that's another debate :)
I'm not sure that the last part is do-able (in a non-hackish way), so yes, including the hash all the time in the default loaders may be the best solution for now after all. Do you want me to create a PR? (edit: I've one ready here)
I really see this PR like this: not something that would be the way to do it, but one way in case someone really needs it. It doesn't really add a lot of overhead and doesn't prevent adding other extensions/presets to the default loaders (such as using the Would you prefer having a |
Yes, please send a PR! I was happy to see your message: I was thinking more about this today and was convinced a hash was the correct behavior (it's also the default behavior of
I'm 👍 on this PR. But yes, I think Thanks! |
a1176d3
to
d975d80
Compare
…fault assets loaders (Lyrkan) This PR was squashed before being merged into the master branch (closes #110). Discussion ---------- Always add a hash to the name of the files created by the default assets loaders This PR modifies the configuration of the default assets loaders so a `[hash]` is always added to the output file names, even if versioning is disabled. It basically prevents having two files with the same name (but in a different directory) overwriting each other during build. This closes #73 and was further discussed in #103. Commits ------- d5cd482 Use [hash:8] for images and fonts filenames instead of [hash] 874235d Modify images/fonts loaders so a hash is always added to the name of output files
Looks perfect to me - 👍 |
d975d80
to
a0cf201
Compare
a0cf201
to
3947d56
Compare
Thank you @Lyrkan! |
I'm trying to reproduce the experiments you took but I don't understand what to do. You mention "Using name: '[path][name].[ext]' and context: './assets'", but where should have I to set those parameters? |
This PR adds a
disableAssetsLoaders
method to the API, allowing users to disable the default image and font loaders.Currently these two loaders are always added (with some parts of them being hardcoded) and can't really be overriden which can causes some issues (see #73).
By allowing to disable this behavior, users would be able to replace them by their own loaders.
About the new method:
Why a
disableAssetsLoaders
and not anenableAssetsLoaders
instead: I still think that these two loaders should be added by default since almost every project will need them. Moreover, keeping them enabled will avoid breaking BC.Why a single method instead of one for the image loader and one for the fonts loader: I may be wrong there, but I think that if an user disable one of them, it'll probably disable the other one aswell anyway.