4chan-x/tools/rollup-plugin-base64.js
Tuxedo Takodachi 0372d676e1 Also minify css.
The minifier didn't keep the newlines anyway.
Also, now I'm working on the build, return empty source mappings for a warning in the console less.
2023-09-08 20:10:32 +02:00

28 lines
699 B
JavaScript

import { readFile } from 'fs/promises';
import { createFilter } from "@rollup/pluginutils";
/**
* @param {{
* include: import("@rollup/pluginutils").FilterPattern,
* exclude?: import("@rollup/pluginutils").FilterPattern,
* }} opts
* @returns {import("rollup").Plugin}
*/
export default function importBase64(opts) {
if (!opts.include) {
throw Error("include option should be specified");
}
const filter = createFilter(opts.include, opts.exclude);
return {
name: "base64",
async load(id) {
if (!filter(id)) return;
const file = await readFile(id);
return { code: `export default '${file.toString('base64')}';`, map: { mappings: '' } };
}
};
};