UNPKG

@intlayer/config

Version:

Retrieve Intlayer configurations and manage environment variables for both server-side and client-side environments.

72 lines (70 loc) 1.92 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const require_runtime = require('../_virtual/_rolldown/runtime.cjs'); let node_path = require("node:path"); let esbuild = require("esbuild"); let node_url = require("node:url"); //#region src/loadExternalFile/bundleFile.ts const getLoader = (extension) => { switch (extension) { case ".js": return "js"; case ".jsx": return "jsx"; case ".mjs": return "js"; case ".ts": return "ts"; case ".tsx": return "tsx"; case ".cjs": return "js"; case ".json": return "json"; case ".md": return "text"; case ".mdx": return "text"; default: return "js"; } }; const getTransformationOptions = (filePath) => ({ loader: { ".js": "js", ".jsx": "jsx", ".mjs": "js", ".ts": "ts", ".tsx": "tsx", ".cjs": "js", ".json": "json", ".md": "text", ".mdx": "text" }, format: "cjs", target: "node16", platform: "neutral", write: false, packages: "bundle", external: ["esbuild"], bundle: true, define: { "import.meta.url": JSON.stringify((0, node_url.pathToFileURL)(filePath).href) } }); const bundleFileSync = (code, filePath, options) => { return (0, esbuild.buildSync)({ stdin: { contents: code, loader: getLoader((0, node_path.extname)(filePath)), resolveDir: (0, node_path.dirname)(filePath), sourcefile: filePath }, ...getTransformationOptions(filePath), ...options }).outputFiles?.[0].text; }; const bundleFile = async (code, filePath, options) => { return (await (0, esbuild.build)({ stdin: { contents: code, loader: getLoader((0, node_path.extname)(filePath)), resolveDir: (0, node_path.dirname)(filePath), sourcefile: filePath }, ...getTransformationOptions(filePath), ...options })).outputFiles?.[0].text; }; //#endregion exports.bundleFile = bundleFile; exports.bundleFileSync = bundleFileSync; exports.getLoader = getLoader; //# sourceMappingURL=bundleFile.cjs.map