"use strict"; const vite = require("vite"); const node_fs = require("node:fs"); const queryRE = /\?.*$/s; const hashRE = /#.*$/s; const cleanUrl = (url) => url.replace(hashRE, "").replace(queryRE, ""); const isDebug = Boolean(process.env.DEBUG); const logger = vite.createLogger("info", { prefix: "[vite-raw-assets]", allowClearScreen: false }); function rawAssetsPlugin({ enforce = "pre", include, exclude } = {}) { let config; const filter = vite.createFilter(include, exclude); return { name: "vite-raw-assets", enforce, configResolved(resolvedConfig) { config = resolvedConfig; }, async load(id) { if (id.startsWith("\0")) { return null; } const file = cleanUrl(id); if (!config.assetsInclude(file) || !filter(file)) { return null; } if (isDebug) { logger.info(`loading ${file}`, { timestamp: true }); } return `export default ${JSON.stringify(await node_fs.promises.readFile(file, "utf-8"))}`; } }; } module.exports = rawAssetsPlugin;