-
-
Notifications
You must be signed in to change notification settings - Fork 100
Open
Description
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 mutating them, which feels a little fragile (esp b/c webpack is so flexible in how it lets you define configuration.)
Some ideas:
- Fancier
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. - More use of
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?
- Add more options to
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. - Have
shakapackerexport a function that takes some user config options and returns a default webpack config with those applied.
Alternatively:
- Document some specific recipes using
webpack-mergeto accomplish this, to the extent it is supported. - Add some names or other metadata to defaults for easier manipulation (to the extent webpack supports doing so.)
Footnotes
-
Specifically I want to add a nonce so that its HMR functionality doesn't create a bunch of spurious CSP violations. ↩