UNPKG

@storm-stack/core

Version:

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

121 lines (116 loc) 3.87 kB
import { resolveESBuildOptions } from './chunk-56IZ2P7I.js'; import { createUnpluginFactory } from './chunk-UKUSXMQ3.js'; import { init_esm_shims, __name } from './chunk-QH7NXH7H.js'; import defu from 'defu'; import { createVitePlugin } from 'unplugin'; import { joinPaths } from '@stryke/path/join-paths'; // src/unplugin/vite.ts init_esm_shims(); // src/lib/vite/options.ts init_esm_shims(); function resolveViteOptions(context, override = {}) { return defu({ resolve: { alias: context.vfs.runtimeIdMap.keys().reduce((ret, id) => { const path = context.vfs.runtimeIdMap.get(id); if (path) { ret[id] = path; } return ret; }, {}) } }, override, context.options.variant === "vite" ? context.options.override : {}, { external: context.options.external, noExternal: context.options.noExternal, skipNodeModulesBundle: context.options.skipNodeModulesBundle }, { rootDir: context.options.sourceRoot, mode: context.options.mode === "development" ? "development" : "production", cacheDir: joinPaths(context.cachePath, "vite"), build: { minify: context.options.mode !== "development", metafile: context.options.mode === "development", sourcemap: context.options.mode === "development", outDir: context.options.output.outputPath, tsconfig: context.tsconfig.tsconfigFilePath, tsconfigRaw: context.tsconfig.tsconfigJson }, esbuild: resolveESBuildOptions(context), assetsInclude: context.options.output.assets, logLevel: context.options.logLevel, envDir: context.options.projectRoot, noExternal: Array.from(context.vfs.runtimeIdMap.keys()) }, context.options.variant === "vite" ? context.options.build : {}, { resolve: { extensions: [ ".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json" ] }, json: { stringify: true }, logLevel: "silent", clearScreen: true }); } __name(resolveViteOptions, "resolveViteOptions"); // src/unplugin/vite.ts var vite = createVitePlugin(createUnpluginFactory({ framework: "vite", decorate: /* @__PURE__ */ __name((engine, plugin) => { return { ...plugin, vite: { async config(config, env) { engine.context.options.isPreview = !!env.isPreview; engine.context.options.isSsrBuild = !!env.isSsrBuild; engine.context.options.mode = env.mode === "development" ? "development" : "production"; const resolvedOptions = resolveViteOptions(engine.context, defu(engine.context.options.override, config)); await engine.hooks.callHook("vite:config", engine.context, { config: resolvedOptions, env }); return resolvedOptions; }, async configResolved(config) { await engine.hooks.callHook("vite:configResolved", engine.context, { config }); }, async configureServer(server) { await engine.hooks.callHook("vite:configureServer", engine.context, { server }); }, async configurePreviewServer(server) { await engine.hooks.callHook("vite:configurePreviewServer", engine.context, { server }); }, async transformIndexHtml(html, ctx) { const result = null; await engine.hooks.callHook("vite:transformIndexHtml", engine.context, { html, ctx, result }); }, async handleHotUpdate(ctx) { const result = null; await engine.hooks.callHook("vite:handleHotUpdate", engine.context, { ctx, result }); } } }; }, "decorate") })); var vite_default = vite; export { vite, vite_default };