UNPKG

@storm-stack/core

Version:

A build toolkit and runtime used by Storm Software in TypeScript applications

57 lines (55 loc) 1.57 kB
import { ModuleResolverPlugin } from './chunk-6J7JLHUX.js'; import { __name } from './chunk-43IZMM3W.js'; import defu from 'defu'; function compilerPlugin(context, options = {}) { const cache = /* @__PURE__ */ new Map(); const handleLoad = /* @__PURE__ */ __name(async (args) => { if (args.path) { const resolvedPath = context.vfs.resolvePath(args.path, { type: "file" }); if (resolvedPath) { if (cache.has(resolvedPath)) { return { contents: cache.get(resolvedPath), pluginData: args.pluginData }; } const contents = await context.vfs.readFile(resolvedPath); if (!contents) { return; } const result = await context.compiler.compile(context, resolvedPath, contents, defu(options, { skipTransformUnimport: true, babel: { plugins: [ ModuleResolverPlugin(context), ...context.options.babel.plugins ] } })); cache.set(args.path, result); return { contents: result, pluginData: args.pluginData }; } } return; }, "handleLoad"); return { name: "storm-stack:compiler", setup(build) { build.onLoad({ filter: /.*/ }, handleLoad); build.onLoad({ filter: /^storm:/ }, handleLoad); } }; } __name(compilerPlugin, "compilerPlugin"); export { compilerPlugin }; //# sourceMappingURL=chunk-VBS6TPPO.js.map //# sourceMappingURL=chunk-VBS6TPPO.js.map