fix(vite, nuxt): resolve relative to srcDir rather than rootDir (#6546)

This commit is contained in:
Daniel Roe 2022-08-12 10:11:09 +01:00 committed by GitHub
parent b0bf25cf51
commit 70b024fbaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 8 deletions

View File

@ -146,7 +146,7 @@ export default defineNuxtModule<ComponentsOptions>({
if (!['add', 'unlink'].includes(event)) { if (!['add', 'unlink'].includes(event)) {
return return
} }
const fPath = resolve(nuxt.options.rootDir, path) const fPath = resolve(nuxt.options.srcDir, path)
if (componentDirs.find(dir => fPath.startsWith(dir.path))) { if (componentDirs.find(dir => fPath.startsWith(dir.path))) {
await nuxt.callHook('builder:generateApp') await nuxt.callHook('builder:generateApp')
} }

View File

@ -53,7 +53,7 @@ export async function buildClient (ctx: ViteBuildContext) {
vuePlugin(ctx.config.vue), vuePlugin(ctx.config.vue),
viteJsxPlugin(), viteJsxPlugin(),
devStyleSSRPlugin({ devStyleSSRPlugin({
rootDir: ctx.nuxt.options.rootDir, srcDir: ctx.nuxt.options.srcDir,
buildAssetsURL: joinURL(ctx.nuxt.options.app.baseURL, ctx.nuxt.options.app.buildAssetsDir) buildAssetsURL: joinURL(ctx.nuxt.options.app.baseURL, ctx.nuxt.options.app.buildAssetsDir)
}), }),
ctx.nuxt.options.experimental.viteNode ctx.nuxt.options.experimental.viteNode

View File

@ -1,7 +1,7 @@
import { resolve } from 'pathe' import { resolve } from 'pathe'
import type { Plugin } from 'vite' import type { Plugin } from 'vite'
export function cacheDirPlugin (rootDir, name: string) { export function cacheDirPlugin (rootDir: string, name: string) {
const optimizeCacheDir = resolve(rootDir, 'node_modules/.cache/vite', name) const optimizeCacheDir = resolve(rootDir, 'node_modules/.cache/vite', name)
return <Plugin> { return <Plugin> {
name: 'nuxt:cache-dir', name: 'nuxt:cache-dir',

View File

@ -3,7 +3,7 @@ import { Plugin } from 'vite'
import { isCSS } from '../utils' import { isCSS } from '../utils'
export interface DevStyleSSRPluginOptions { export interface DevStyleSSRPluginOptions {
rootDir: string srcDir: string
buildAssetsURL: string buildAssetsURL: string
} }
@ -18,8 +18,8 @@ export function devStyleSSRPlugin (options: DevStyleSSRPluginOptions): Plugin {
} }
let moduleId = id let moduleId = id
if (moduleId.startsWith(options.rootDir)) { if (moduleId.startsWith(options.srcDir)) {
moduleId = moduleId.slice(options.rootDir.length) moduleId = moduleId.slice(options.srcDir.length)
} }
// When dev `<style>` is injected, remove the `<link>` styles from manifest // When dev `<style>` is injected, remove the `<link>` styles from manifest

View File

@ -7,7 +7,7 @@ import { getViteNodeOptions } from './vite-node-shared.mjs'
const viteNodeOptions = getViteNodeOptions() const viteNodeOptions = getViteNodeOptions()
const runner = new ViteNodeRunner({ const runner = new ViteNodeRunner({
root: viteNodeOptions.rootDir, root: viteNodeOptions.root, // Equals to Nuxt `srcDir`
base: viteNodeOptions.base, base: viteNodeOptions.base,
async fetchModule (id) { async fetchModule (id) {
return await $fetch('/module/' + encodeURI(id), { return await $fetch('/module/' + encodeURI(id), {

View File

@ -143,7 +143,7 @@ export async function initViteNodeServer (ctx: ViteBuildContext) {
// Serialize and pass vite-node runtime options // Serialize and pass vite-node runtime options
const viteNodeServerOptions = { const viteNodeServerOptions = {
baseURL: `${protocol}://${host}:${port}/__nuxt_vite_node__`, baseURL: `${protocol}://${host}:${port}/__nuxt_vite_node__`,
rootDir: ctx.nuxt.options.rootDir, root: ctx.nuxt.options.srcDir,
entryPath, entryPath,
base: ctx.ssrServer.config.base || '/_nuxt/' base: ctx.ssrServer.config.base || '/_nuxt/'
} }