richardtallent / vite-plugin-singlefile

Vite plugin for inlining JavaScript and CSS resources
MIT License
859 stars 58 forks source link

New config option request: specify what to inline, css or javascript #31

Closed ezhlobo closed 2 years ago

ezhlobo commented 2 years ago

It will be handy to specify what exactly we should inline. Sometimes it's handy to inline just css and leave javascript to be loaded.

In my use case I build browser extension and it would be great to save a tiny loading time by not doing extra request to load stylesheets. In other hand those extensions prohibit inline scripts and I'd want to keep lazy loading too.

Even though for my use case I can find solutions, I believe it's logical for this plugin to configure what exactly we want to inline.

Greenheart commented 2 years ago

I've got projects where a feature like this would be nice. I think a glob pattern (or RegExp) specifying which files to include would solve this in a nice way.

The default behavior should still be to inline all JS and CSS, like the name of the plugin. However, we could add an optional parameter inlinePattern which could be a glob pattern or RegExp that is tested against all asset file names (JS and CSS). If an asset matches the inlinePattern, it gets inlined. This would effectively allow plugin users to only include CSS files with *.css for example, and only specific JS files with vendor.js

Suggested library to test a string against a glob pattern: https://github.com/micromatch/micromatch

richardtallent commented 2 years ago

Please try 0.10.0-beta, I've added this option.

Greenheart commented 2 years ago

Thanks @richardtallent! I'll check this out in my upcoming projects :smile:

richardtallent commented 2 years ago

0.10.0 has been released.