UNPKG

vike

Version:

The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.

42 lines (41 loc) 1.31 kB
import '../../assertEnvVite.js'; export { pluginDistPackageJsonFile }; import { rollupIsEsm } from '../../shared/rollupIsEsm.js'; import { isViteServerSide } from '../../shared/isViteServerSide.js'; function pluginDistPackageJsonFile() { let config; return [ { name: 'vike:build: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" }`; } }