UNPKG

telefunc

Version:

Remote functions. Instead of API.

41 lines (40 loc) 1.27 kB
export { pluginDistPackageJsonFile }; import { rollupIsEsm } from '../shared/rollupIsEsm.js'; import { isViteServerSide } from '../shared/isViteServerSide.js'; function pluginDistPackageJsonFile() { let config; return [ { name: 'telefunc:pluginDistPackageJsonFile', apply: 'build', configResolved: { handler(config_) { config = config_; }, }, generateBundle: { handler(options, bundle) { if (!isViteServerSide(config, this.environment)) return; const isEsm = rollupIsEsm(options); const fileName = 'package.json'; if (bundle[fileName]) return; // E.g. already generated by Telefunc / Vike this.emitFile({ fileName, type: 'asset', source: getPackageJsonContent(isEsm), }); }, }, }, ]; } function getPackageJsonContent(isEsm) { if (isEsm) { return `{ "type": "module" }`; } else { return `{ "type": "commonjs" }`; } }