Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

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

Merged
merged 4 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/nuxt/src/components/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default defineNuxtModule<ComponentsOptions>({
if (!['add', 'unlink'].includes(event)) {
return
}
const fPath = resolve(nuxt.options.rootDir, path)
const fPath = resolve(nuxt.options.srcDir, path)
if (componentDirs.find(dir => fPath.startsWith(dir.path))) {
await nuxt.callHook('builder:generateApp')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function buildClient (ctx: ViteBuildContext) {
vuePlugin(ctx.config.vue),
viteJsxPlugin(),
devStyleSSRPlugin({
rootDir: ctx.nuxt.options.rootDir,
srcDir: ctx.nuxt.options.srcDir,
buildAssetsURL: joinURL(ctx.nuxt.options.app.baseURL, ctx.nuxt.options.app.buildAssetsDir)
}),
ctx.nuxt.options.experimental.viteNode
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/plugins/cache-dir.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolve } from 'pathe'
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)
return <Plugin> {
name: 'nuxt:cache-dir',
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/plugins/dev-ssr-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Plugin } from 'vite'
import { isCSS } from '../utils'

export interface DevStyleSSRPluginOptions {
rootDir: string
srcDir: string
buildAssetsURL: string
}

Expand All @@ -18,8 +18,8 @@ export function devStyleSSRPlugin (options: DevStyleSSRPluginOptions): Plugin {
}

let moduleId = id
if (moduleId.startsWith(options.rootDir)) {
moduleId = moduleId.slice(options.rootDir.length)
if (moduleId.startsWith(options.srcDir)) {
moduleId = moduleId.slice(options.srcDir.length)
}

// When dev `<style>` is injected, remove the `<link>` styles from manifest
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/runtime/vite-node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getViteNodeOptions } from './vite-node-shared.mjs'
const viteNodeOptions = getViteNodeOptions()

const runner = new ViteNodeRunner({
root: viteNodeOptions.rootDir,
root: viteNodeOptions.root,
pi0 marked this conversation as resolved.
Show resolved Hide resolved
base: viteNodeOptions.base,
async fetchModule (id) {
return await $fetch('/module/' + encodeURI(id), {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/vite-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export async function initViteNodeServer (ctx: ViteBuildContext) {
// Serialize and pass vite-node runtime options
const viteNodeServerOptions = {
baseURL: `${protocol}://${host}:${port}/__nuxt_vite_node__`,
rootDir: ctx.nuxt.options.rootDir,
root: ctx.nuxt.options.srcDir,
antfu marked this conversation as resolved.
Show resolved Hide resolved
entryPath,
base: ctx.ssrServer.config.base || '/_nuxt/'
}
Expand Down