embroider-build / embroider

Compiling Ember apps into spec-compliant, modern Javascript.
MIT License
339 stars 137 forks source link

rollup `addon.keepAssets()` "eating" created assets #1253

Open gossi opened 2 years ago

gossi commented 2 years ago

I realized a weird behavior, where addon.keepAssets().... which is "eating" my newly created assets :cookie: The relevant part of my rollup config:

plugins: [
  postcss({...}),
  // ... snip ...
  addon.keepAssets(['**/*.css'])
]

1) postcss (from rollup-plugin-postcss) - it is configured to compile all *.css files into one styles.css file at the root (through css modules and it works) 2) with addon.keepAssets() I want to keep the source css files (to export them, so others can compose from them)

Now what is happening:

I tried to glob the styles file away with addon.keepAssets('['**/!(styles).css']') - but no change.

Given the order in which rollup plugins are executed and their side-effects on each other is unclear to me, I don't understand this 🤷

Does addon.keepAssets() interfere with the other plugins? Is that a potential reason for my observed behavior? Where else I might have to look?

ef4 commented 2 years ago

I think keepAssets doesn't have any support right now for composing with a preprocessor like postcss.

If your plan is to ship a single prebuilt CSS file, it's probably easier to not use keepAssets and only use postcss and just make sure it emits its file into the place where you want it to be (probably /dist).

keepAssets was made for the case where your Javascript has imports that refer to some assets files and you want rollup to leave those imports alone so that decisions about incorporating them can be left up to the consuming application. This is ideal when there are some assets that are always tied to a particular component, because that component can import them and then they're only ever loaded if the component is used.

A combined CSS file is also fine, if you're going to manually tell users that they're supposed to import it. This gives them an easier way to extend and override the styles, at the cost of moving more manual decisions to the users.