-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
Add Encore.configureUrlLoader() method to the public API #296
Conversation
700d7a9
to
0ba2677
Compare
lib/config-generator.js
Outdated
|
||
if (this.webpackConfig.urlLoaderOptions.images) { | ||
loaderName = 'url-loader'; | ||
loaderOptions = this.webpackConfig.urlLoaderOptions.images; |
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.
the file-loader options must be combined with the url-loader options. Otherwise, we won't have the right config in case the url-loader fallbacks to the file-loader for bigger files.
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.
Definitely, should be good now!
package.json
Outdated
@@ -43,6 +43,7 @@ | |||
"pretty-error": "^2.1.1", | |||
"resolve-url-loader": "^2.0.2", | |||
"style-loader": "^0.13.2", | |||
"url-loader": "^1.0.1", |
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.
should it actually be a requirement for everyone using Encore ? This is an opt-in feature.
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.
Yep, I hesitated a bit on that one but ended-up adding it as a main dependency without any good reason.
I moved it to dev dependencies and added the usual ensurePackageExist
checks.
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.
Can you also create PR on the docs? Because, this will definitely be merged :)
if (validKeys.indexOf(key) === -1) { | ||
throw new Error(`"${key}" is not a valid key for configureUrlLoader(). Valid keys: ${validKeys.join(', ')}.`); | ||
} | ||
} |
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.
Yay for validation :)
@Lyrkan thank you so much for this PR |
Thank you @Lyrkan! I've wanted this feature for awhile :) |
… (Lyrkan) This PR was squashed before being merged into the master branch (closes #296). Discussion ---------- Add Encore.configureUrlLoader() method to the public API This PR adds a `configureUrlLoader()` method to the public API in order to allow the use of the `url-loader` instead of the `file-loader` for images and fonts (closes #295). Usage: ```js // Enable the url-loader for both images and fonts Encore.configureUrlLoader({ images: { limit: 8192, mimetype: 'image/png' }, fonts: { limit: 4096 } }); // Enable the url-loader for images and implicitly // disable it for fonts (by omitting the "fonts" key) Encore.configureUrlLoader({ images: { limit: 8192, mimetype: 'image/png' } }); // Enable the url-loader for fonts and explicitly // disable it for images (by using a falsy value // for the "images" key). Encore.configureUrlLoader({ images: false, fonts: { limit: 4096 } }); ``` Commits ------- 92ea9c4 Encore.configureUrlLoader() - Replace some 'let' by 'const' 9ca96a5 Encore.configureUrlLoader() - Move url-loader to dev dependencies 69e2cfe Encore.configureUrlLoader() - Merge options instead of replacing them 0ba2677 Add Encore.configureUrlLoader() method to the public API
I'll try to add some doc for it next week! |
👍 so awesome this made my night. :) |
@Lyrkan thanks for volunteering to write some docs about this. Reading the examples of the descriptions, these are my main doubts:
Thanks! |
@javiereguiluz These options are the ones provided by the URL loader, not something we added on our side:
|
…n, javiereguiluz) This PR was merged into the 3.4 branch. Discussion ---------- [Encore] Encore.configureUrlLoader() documentation This PR adds the documentation for the `Encore.configureUrlLoader()` method (symfony/webpack-encore#296). Not sure if it should be more detailed since the other options of the URL loader are typically not needed... Commits ------- 5c87901 Use the default article title 4d8700f Reword 6820867 Encore.configureUrlLoader() documentation
This PR adds a
configureUrlLoader()
method to the public API in order to allow the use of theurl-loader
instead of thefile-loader
for images and fonts (closes #295).Usage: