UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

82 lines (77 loc) 3 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var virtualEntryPlugin_exports = {}; __export(virtualEntryPlugin_exports, { createVirtualEntry: () => createVirtualEntry }); module.exports = __toCommonJS(virtualEntryPlugin_exports); var import_vxrn = require("vxrn"), import_virtualEntryConstants = require("./virtualEntryConstants"), USE_ONE_SETUP_FILE = ` if (process.env.ONE_SETUP_FILE) { import(/* @vite-ignore */ process.env.ONE_SETUP_FILE) } `; function createVirtualEntry(options) { var appDirGlob = `/${options.root}/**/*.tsx`, appDirApiGlob = `/${options.root}/**/*+api.tsx`; return { name: "one-virtual-entry", enforce: "pre", resolveId(id) { if (id === import_virtualEntryConstants.virtualEntryId) return import_virtualEntryConstants.resolvedVirtualEntryId; if (id === import_virtualEntryConstants.virtualEntryIdNative) return import_virtualEntryConstants.resolvedVirtualEntryIdNative; }, load(id) { if (id === import_virtualEntryConstants.resolvedVirtualEntryId) { var prependCode = (0, import_vxrn.isNativeEnvironment)(this.environment) ? "" : ( /* `import()` will not work on native */ USE_ONE_SETUP_FILE ); return ` ${prependCode} import { createApp } from 'one' // globbing ${appDirGlob} export default createApp({ routes: import.meta.glob('${appDirGlob}', { exhaustive: true }), routerRoot: ${JSON.stringify(options.root)}, flags: ${JSON.stringify(options.flags)}, }) `; } if (id === import_virtualEntryConstants.resolvedVirtualEntryIdNative) { var prependCode1 = (0, import_vxrn.isNativeEnvironment)(this.environment) ? "" : ( /* `import()` will not work on native */ USE_ONE_SETUP_FILE ); return ` ${prependCode1} import { createApp } from 'one' // globbing ${appDirGlob} export default createApp({ routes: import.meta.glob(['${appDirGlob}', '!${appDirApiGlob}'], { exhaustive: true }), routerRoot: ${JSON.stringify(options.root)}, flags: ${JSON.stringify(options.flags)}, }) `; } } }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { createVirtualEntry }); //# sourceMappingURL=virtualEntryPlugin.js.map