From 91c6ef57e71c9acd7472c82b853bc7c89fac71a4 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 11 Aug 2021 23:26:47 +0200 Subject: [PATCH] fix(nuxt3): resolve dist dir by top level module --- packages/nuxt3/src/components/module.ts | 3 ++- packages/nuxt3/src/core/nuxt.ts | 4 ++-- packages/nuxt3/src/dirs.ts | 4 ++++ packages/nuxt3/src/meta/module.ts | 3 ++- packages/nuxt3/src/pages/module.ts | 3 ++- 5 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 packages/nuxt3/src/dirs.ts diff --git a/packages/nuxt3/src/components/module.ts b/packages/nuxt3/src/components/module.ts index 9725ec7357..958f3bec36 100644 --- a/packages/nuxt3/src/components/module.ts +++ b/packages/nuxt3/src/components/module.ts @@ -1,6 +1,7 @@ import { statSync } from 'fs' import { resolve, relative } from 'upath' import { defineNuxtModule, resolveAlias, addVitePlugin, addWebpackPlugin } from '@nuxt/kit' +import { distDir } from '../dirs' import { scanComponents } from './scan' import type { Component, ComponentsDir } from './types' import { loaderPlugin } from './loader' @@ -66,7 +67,7 @@ export default defineNuxtModule({ app.templates.push({ filename: 'components.mjs', - src: resolve(__dirname, 'runtime/components.tmpl.mjs'), + src: resolve(distDir, 'pages/runtime/components.tmpl.mjs'), options: { components } }) diff --git a/packages/nuxt3/src/core/nuxt.ts b/packages/nuxt3/src/core/nuxt.ts index 1cbbb82719..a075996e25 100644 --- a/packages/nuxt3/src/core/nuxt.ts +++ b/packages/nuxt3/src/core/nuxt.ts @@ -5,6 +5,7 @@ import pagesModule from '../pages/module' import metaModule from '../meta/module' import componentsModule from '../components/module' import globalImportsModule from '../global-imports/module' +import { distDir, pkgDir } from '../dirs' import { initNitro } from './nitro' export function createNuxt (options: NuxtOptions): Nuxt { @@ -55,11 +56,10 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise { const options = loadNuxtConfig(opts) // Temp - const distDir = resolve(__dirname, '..') options.appDir = options.alias['#app'] = resolve(distDir, 'app') options._majorVersion = 3 options.buildModules.push(pagesModule, metaModule, componentsModule, globalImportsModule) - options.modulesDir.push(resolve(distDir, '../node_modules')) + options.modulesDir.push(resolve(pkgDir, 'node_modules')) const nuxt = createNuxt(options) diff --git a/packages/nuxt3/src/dirs.ts b/packages/nuxt3/src/dirs.ts new file mode 100644 index 0000000000..ee18994286 --- /dev/null +++ b/packages/nuxt3/src/dirs.ts @@ -0,0 +1,4 @@ +import { resolve } from 'upath' + +export const distDir = __dirname +export const pkgDir = resolve(distDir, '..') diff --git a/packages/nuxt3/src/meta/module.ts b/packages/nuxt3/src/meta/module.ts index 7588ac7a82..1b6137fd15 100644 --- a/packages/nuxt3/src/meta/module.ts +++ b/packages/nuxt3/src/meta/module.ts @@ -1,5 +1,6 @@ import { resolve } from 'upath' import { addPlugin, addTemplate, defineNuxtModule } from '@nuxt/kit' +import { distDir } from '../dirs' import type { MetaObject } from './types' export default defineNuxtModule({ @@ -9,7 +10,7 @@ export default defineNuxtModule({ viewport: 'width=device-width, initial-scale=1' }, setup (options, nuxt) { - const runtimeDir = resolve(__dirname, 'runtime') + const runtimeDir = resolve(distDir, 'meta/runtime') // Transpile @nuxt/meta and @vueuse/head nuxt.options.build.transpile.push(runtimeDir, '@vueuse/head') diff --git a/packages/nuxt3/src/pages/module.ts b/packages/nuxt3/src/pages/module.ts index 2be310778a..cac539a98f 100644 --- a/packages/nuxt3/src/pages/module.ts +++ b/packages/nuxt3/src/pages/module.ts @@ -1,13 +1,14 @@ import { existsSync } from 'fs' import { defineNuxtModule, addTemplate, addPlugin } from '@nuxt/kit' import { resolve } from 'upath' +import { distDir } from '../dirs' import { resolveLayouts, resolvePagesRoutes } from './utils' export default defineNuxtModule({ name: 'router', setup (_options, nuxt) { const pagesDir = resolve(nuxt.options.srcDir, nuxt.options.dir.pages) - const runtimeDir = resolve(__dirname, 'runtime') + const runtimeDir = resolve(distDir, 'pages/runtime') // Disable module if pages dir do not exists if (!existsSync(pagesDir)) {