open-pioneer / trails-build-tools

Build tools for the Open Pioneer Trails web client framework.
Apache License 2.0
2 stars 0 forks source link

Output .css file for styles instead of js strings #59

Open antoniave opened 1 year ago

antoniave commented 1 year ago

Currently we are embedding the final styles for an application as a JavaScript string, i.e. const styles = "..." which is then loaded into a <style> tag.

This is triggered in our vite plugin, where we import the 'combined' css using the &inline query parameter, which prompts vite to return a raw css string to us (see https://github.com/open-pioneer/build-tools/blob/10112f6dfe15361e68fb48633d322b356fc20e7d/packages/vite-plugin/src/codegen/generateAppMetadata.ts#LL28C5-L29C88).

This approach has a number of disadvantages:

The &inline should be replaced by an &url, which would trigger vite to emit a .css asset and return its URL, not its content.

However, this was (and probably is still) blocked by https://github.com/vitejs/vite/issues/2522 (context: our topmost css "entry point" uses SCSS to support both SCSS and CSS). There is an open pull request but there has been no progress for some time.

mbeckem commented 6 months ago

Should be doable now with vite >= 5