Skip to content

Conversation

kellymears
Copy link
Contributor

@kellymears kellymears commented Dec 28, 2021

Type of change

  • MINOR: feature

Dependencies added

  • none

Details

  • updated tests
  • updated all rule modifying extensions

Modifying rules is kind of a pain. This makes it a lot easier to set up a rule without needing to import the Rule constructor, etc.

old:

app.build.rules.html = new Rule(app, {
  test: ({store}) => store.get('patterns.html'),
  use: ({build}) => [build.items.html],
})

new:

app.build.setRule('html', {
test: ({store}) => store.get('patterns.html'),
use: ({build}) => [build.items.html],
})

or, treat it like a factory (don't set it)

const myRule = app.build.makeRule({
 test: ({store}) => store.get('patterns.html'),
 use: ({build}) => [build.items.html],
})
 
// later you can assign it
Object.assign(app.build.rules, {myRule})

and/or do some funky chaining:

app.build
  .makeRule()
  .setTest(({store}) => store.get('patterns.font'))
  .setExclude(({store}) => store.get('patterns.modules'))
  .setType('asset')
  .setGenerator({filename: 'assets/[name][ext]'})
  .setParser({
    dataUrlCondition: {
      maxSize: 50000,
    },
  })

Lastly, in order to interact with a rule you'd need to manually pass the bud instance to any of the getters, which was weird:

app.build.rules.js.getTest(app)

No longer as weird:

app.build.rules.js.getTest()

I think this will become a bigger deal as more people want to do stuff like import assets from node_modules or other things bud doesn't support out-of-the-box because of the performance implications. @QWp6t had the idea of making that a facade-level function and this is the first step towards that, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant