one
Version:
One is a new React Framework that makes Vite serve both native and web.
56 lines (51 loc) • 1.79 kB
JavaScript
import { isNativeEnvironment } from "vxrn";
import { resolvedVirtualEntryId, resolvedVirtualEntryIdNative, virtualEntryId, virtualEntryIdNative } from "./virtualEntryConstants.native.js";
var 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 === virtualEntryId) return resolvedVirtualEntryId;
if (id === virtualEntryIdNative) return resolvedVirtualEntryIdNative;
},
load(id) {
if (id === resolvedVirtualEntryId) {
var prependCode = 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 === resolvedVirtualEntryIdNative) {
var prependCode1 = 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)},
})
`;
}
}
};
}
export { createVirtualEntry };
//# sourceMappingURL=virtualEntryPlugin.native.js.map