bun-asset-loader
v1.2.2
Published
Bun plugin for loading non-imported assets
Downloads
3,664
Maintainers
Readme
bun i -D bun-asset-loader
About
This plugin incorporates custom filtered assets into the output directory by copying and optionally modifying them.
It is designed for files that are not imported in any source files.
Please note: Only works on non-Windows based operating systems.
How-To
import assetLoader from 'bun-asset-loader';
const options = {
assets: [
{
from: 'path/to/css/file',
to: 'path/to/outdir',
minify: true, // minify CSS, HTML, JSON, etc.
},
{
from: 'path/to/dir',
to: 'path/to/outdir/subdir',
filter: /\.(png|jpe?g)$/i, // accepts RegEx and glob patterns
},
{
from: 'path/to/dir',
// 'to' can be omitted - uses Bun.build 'outdir' as fallback
filter: '*.json',
name: 'newName.json',
transform: (content) => {
// make the needed changes to the content
const transformedContent = ... // transform content
return JSON.stringify(transformedContent);
},
},
],
};
await Bun.build({
// ...
plugins: [
// ...
assetLoader(options),
],
});
License
Distributed under the MIT License. See MIT License for more information.