-
-
Notifications
You must be signed in to change notification settings - Fork 97
Easier granular opt-out of defaults #80
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
Comments
@dleavitt I appreciate this work! The current system relies on webpack-merge and plain JS coding on top of the base defaults. I'm concerned that we create too many alternatives for accomplishing the same thing. Let's think about this some more. And some doc example recipes should always be appreciated! |
I thought a bit more about this. I agree that it might be nice to allow including some module but opting out of the default customization. |
I'll take a stab at the docs with the examples of customisation. Will also document what are the default rules.
Seems like great thing to do, if possible. Being able to reference rules based on some name rather than trying to find it by the rule test should simplify this a bit. @justin808 In #87 (comment) you've mentioned an idea of |
Thanks @justin808! Not sure if I'll get around to it this week but definitely something I'd be happy to help with or review. |
Closed as stale. |
@dleavitt we could also create a "discussion" on doc issues. |
I'm glad I managed to come across this issue. I was worried I was going about things in a hacky way. Still kind of am actually. I wanted to silence some warnings from sass since one of my dependencies (@materializecss/materialize) hasn't updated it's usage of map-has-key and map-get yet and ended up doing this in my config/webpack/webpack.config.js:
Which produces the following options for the sass loader:
Which is what I was aiming for. From your comment Justin it sounds like this is the intended way of going about this sort of config change. If that's the case, it might be a good idea to explicitly document a use case like mine. The readme does include a note at the end of the webpack config section (https://github.com/shakacode/shakapacker?tab=readme-ov-file#webpack-configuration) which mentions modifying a rule produced by the default config but it was not at all obvious to me that I could/should use this method for modifying the config for a loader (in hindsight it seems kind of obvious now though). I think a couple of more complex examples of changing the default config and explicitly calling out changing the config for a loader would do much to clear up any potential confusion here. Edit: If my use case is how this is supposed to work and you think would make a good example in the readme I'd be happy to submit a PR. |
Ruby version: 3.1.1
Rails version: 7.0.2
Webpacker version: 6.1.1
Desired behavior:
I want to tweak the style-loader options 1 but otherwise opt-in to the excellent webpack defaults provided.
Actual behavior:
As far as I can tell it's a little harder to do this now that loaders/plugins etc aren't named. I'm currently digging through the list of rules and matching on the "test" values, then mutation them, which feels a little fragile (esp b/c webpack is so flexible in how it lets you define configuration.)
Some ideas:
moduleExists
: right now this function is used pretty heavily to determine what defaults to use. Instead of just checking for the existence of a module, it could tie in with some config and always return false if the user wants to opt-out of certain defaults.getCustomConfig
: swc and esbuild integrations allow the user to add a specially named config file within their app that can override defaults (littering the config folder with js snippets doesn't seem great though, see below.)How does the user specify the config?
webpacker.yml
: this is done right now for a few options (inline_css
,webpack_loader
) but maybe better to keep this file mostly about things ruby and webpack both need to know about.shakapacker
export a function that takes some user config options and returns a default webpack config with those applied.Alternatively:
webpack-merge
to accomplish this, to the extent it is supported.Footnotes
Specifically I want to add a nonce so that its HMR functionality doesn't create a bunch of spurious CSP violations. ↩
The text was updated successfully, but these errors were encountered: