fix(vite): set vite's root to current directory (#239)

This commit is contained in:
Anthony Fu 2021-07-14 22:40:40 +08:00 committed by GitHub
parent 9e8b042bad
commit d995e83a31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View File

@ -6,6 +6,6 @@
<body {{ BODY_ATTRS }}>
{{ APP }}
<% if (nuxt.options.vite && nuxt.options.dev) { %><script type="module" src="/@vite/client"></script>
<script type="module" src="/entry.mjs"></script><% } %>
<script type="module" src="/__build/entry.mjs"></script><% } %>
</body>
</html>

View File

@ -28,7 +28,7 @@ export async function buildServer (ctx: ViteBuildContext) {
]
},
build: {
outDir: 'dist/server',
outDir: resolve(ctx.nuxt.options.buildDir, 'dist/server'),
ssr: true,
rollupOptions: {
input: resolve(ctx.nuxt.options.buildDir, 'entry.mjs'),

View File

@ -23,7 +23,7 @@ export async function bundle (nuxt: Nuxt) {
config: vite.mergeConfig(
nuxt.options.vite as any || {},
{
root: nuxt.options.buildDir,
root: nuxt.options.rootDir,
mode: nuxt.options.dev ? 'development' : 'production',
logLevel: 'warn',
define: {
@ -35,6 +35,7 @@ export async function bundle (nuxt: Nuxt) {
...nuxt.options.alias,
'#build': nuxt.options.buildDir,
'#app': nuxt.options.appDir,
'/__build': nuxt.options.buildDir,
'~': nuxt.options.srcDir,
'@': nuxt.options.srcDir,
'web-streams-polyfill/ponyfill/es2018': 'unenv/runtime/mock/empty',
@ -76,7 +77,7 @@ export async function bundle (nuxt: Nuxt) {
nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer) => {
const start = Date.now()
warmupViteServer(server, ['/entry.mjs']).then(() => {
warmupViteServer(server, [`/@fs${nuxt.options.buildDir.replace(/\\/g, '/')}/entry.mjs`]).then(() => {
consola.info(`Vite warmed up in ${Date.now() - start}ms`)
}).catch(consola.error)
})