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 }}> <body {{ BODY_ATTRS }}>
{{ APP }} {{ APP }}
<% if (nuxt.options.vite && nuxt.options.dev) { %><script type="module" src="/@vite/client"></script> <% 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> </body>
</html> </html>

View File

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

View File

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