-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
feat: make Webpack url-loader limit configurable (env variable) #5498
Conversation
…nment variable 'URL_LOADER_LIMIT'.
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.
LGTM as a temporary solution. I think this is a good change for the time being.
✔️ [V2] 🔨 Explore the source changes: 3743375 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/614a3b75cb81270007a2013e 😎 Browse the preview: https://deploy-preview-5498--docusaurus-2.netlify.app |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-5498--docusaurus-2.netlify.app/ |
Co-authored-by: Joshua Chen <[email protected]>
Thanks, agree this is a good-enough temporary change. file-loader and url-loader are going to be deprecated someday and we'll migrate to the new asset system (POC #4708) so we'll avoid documenting this on purpose because the API surface is not ideal and we'll likely do a breaking change. |
const urlLoaderLimit = 10000; | ||
// files/images < 10kb (overridable via 'URL_LOADER_LIMIT' environment | ||
// variable) will be inlined as base64 strings directly in the html | ||
const urlLoaderLimit = process.env.URL_LOADER_LIMIT ?? 10000; |
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.
Have you tested this locally? Afaik process.env.URL_LOADER_LIMIT
would be a string, shouldn't it be converted to a number?
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 suggest:
- moving it to
packages/docusaurus/src/constants.ts
- name it
WEBPACK_ URL_LOADER_LIMIT
- add comment to say it's temporary, link to this PR/issue
We'd rather centralize all those undocumented env variables in a single place
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.
Have you tested this locally? Afaik
process.env.URL_LOADER_LIMIT
would be a string, shouldn't it be converted to a number?
The loader accepts number | string.
I'll move the const and rename the ENV VAR as per your suggestion.
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.
Done.
const urlLoaderLimit = 10000; | ||
// files/images < 10kb (overridable via 'URL_LOADER_LIMIT' environment | ||
// variable) will be inlined as base64 strings directly in the html | ||
const urlLoaderLimit = process.env.URL_LOADER_LIMIT ?? 10000; |
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 suggest:
- moving it to
packages/docusaurus/src/constants.ts
- name it
WEBPACK_ URL_LOADER_LIMIT
- add comment to say it's temporary, link to this PR/issue
We'd rather centralize all those undocumented env variables in a single place
* moving it to packages/docusaurus/src/constants.ts * name it WEBPACK_ URL_LOADER_LIMIT * add comment to say it's temporary, link to this PR/issue
Thanks So it does work fine without using |
Looks like it accepts a string indeed: |
I stumbled upon this when I was writing up how to use the The workaround works... but it's not great developer experience. @slorber would you be open to having this configured more directly somehow? Perhaps using the |
@johnnyreilly what would be the api so that it's not overwhelming for 99% users not needing this option? |
So @slorber my thought is that this would be optional - you only use it if you need to use it; by default you don't. Most folks wouldn't use this. I don't have particular thoughts on what the API should be but here's an idea (you may not like it, but it could start the ball rolling). The configuration we want to tweak lives in this file: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-utils/src/constants.ts The existing
Imagine a docusaurus option called It would be a power user feature to be sure - most people wouldn't use this. What do you think? |
Motivation
Fixes #5493
Have you read the Contributing Guidelines on pull requests?
Yes.
Test Plan
yarn run start:website
should work as beforepackage.json
and changeyarn run start:website
tocross-env URL_LOADER_LIMIT=999999 yarn workspace website start
. The new limit should be in effect. I tested this by printing out the value of the const in the affected file.