Skip to content

Commit 4c94323

Browse files
committed
minor #20755 Documenting the configureCssLoader method (Jalen Muller)
This PR was merged into the 7.3 branch. Discussion ---------- Documenting the configureCssLoader method This is something that I've searched for for at least an hour before finding it referenced in a GitHub issue. So this PR is to help other developers trying to configure the CSS loader. See the `css-loader` docs where it's documented in their main `README` https://github.com/webpack-contrib/css-loader?tab=readme-ov-file#object Commits ------- ea5d2cf Document the `configureCssLoader` method
2 parents e9a6bd4 + ea5d2cf commit 4c94323

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

frontend/encore/advanced-config.rst

+26
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,32 @@ Now you can inject your service into your class::
198198
$this->render($emailTwo);
199199
}
200200

201+
Configuring the CSS Loader
202+
--------------------------
203+
204+
Encore provides the method ``configureCssLoader()`` to configure options for ``css-loader``. This method allows you to customize how Webpack processes CSS assets.
205+
206+
A common use case is filtering certain URLs so that Webpack does not attempt to resolve them. For example, if user-uploaded assets are stored under in a user uploaded directory, Webpack should not process these paths since they may not exist at build time.
207+
208+
Use ``configureCssLoader()`` as follows:
209+
210+
.. code-block:: javascript
211+
212+
// Configuring the CSS Loader in Webpack Encore
213+
// This ensures that Webpack does not attempt to resolve certain URLs in CSS files
214+
215+
Encore.configureCssLoader((options) => {
216+
options.url = {
217+
filter: (url) => {
218+
// Ignore URLs that start with /uploads/
219+
if (url.startsWith('/uploads/')) {
220+
return false;
221+
}
222+
return true; // Process other URLs normally
223+
},
224+
};
225+
});
226+
201227
Generating a Webpack Configuration Object without using the Command-Line Interface
202228
----------------------------------------------------------------------------------
203229

0 commit comments

Comments
 (0)