diff --git a/src/node/plugin.ts b/src/node/plugin.ts index fc6d8e6fd146..4f6037c082f2 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -1,4 +1,5 @@ import path from 'path' +import fs from 'fs-extra' import { defineConfig, mergeConfig, Plugin, ResolvedConfig } from 'vite' import { SiteConfig, resolveSiteData } from './config' import { @@ -276,6 +277,15 @@ export function createVitePressPlugin( // overwrite src so vue plugin can handle the HMR ctx.read = () => vueSrc } + }, + + writeBundle(_options) { + if (ssr && _options.dir && _options.format === 'cjs') { + fs.writeFileSync( + path.join(_options.dir, 'package.json'), + JSON.stringify({ type: 'commonjs' }) + ) + } } }