fix: ERR_REQUIRE_ESM error when project type is set to module

pull/512/head
Titouan Mathis 4 years ago
parent 45b65ce8b6
commit 781718c2e9
No known key found for this signature in database
GPG Key ID: A292A3DB3103F19D

@ -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' })
)
}
}
}

Loading…
Cancel
Save