@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
63 lines (58 loc) • 1.82 kB
JavaScript
;
var chunkZC2JNV4B_cjs = require('./chunk-ZC2JNV4B.cjs');
var chunk3ONWID2V_cjs = require('./chunk-3ONWID2V.cjs');
var defu = require('defu');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var defu__default = /*#__PURE__*/_interopDefault(defu);
function compilerPlugin(context, options = {}) {
const cache = /* @__PURE__ */ new Map();
const handleLoad = /* @__PURE__ */ chunk3ONWID2V_cjs.__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__default.default(options, {
skipTransformUnimport: true,
babel: {
plugins: [
chunkZC2JNV4B_cjs.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);
}
};
}
chunk3ONWID2V_cjs.__name(compilerPlugin, "compilerPlugin");
exports.compilerPlugin = compilerPlugin;
//# sourceMappingURL=chunk-UY2GAVJJ.cjs.map
//# sourceMappingURL=chunk-UY2GAVJJ.cjs.map