Skip to content

Commit

Permalink
fix(nuxt): useNuxtApp error
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Sep 24, 2023
1 parent 418588d commit d8bb144
Show file tree
Hide file tree
Showing 6 changed files with 1,882 additions and 170 deletions.
9 changes: 9 additions & 0 deletions examples/nuxt3/cypress/e2e/all-stories.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="cypress" />

describe('Stories list', () => {
it('should display all stories', () => {
cy.clearLocalStorage()
cy.visit('/')
cy.get('[data-test-id="story-list-item"]').should('have.length', 4)
})
})
4 changes: 2 additions & 2 deletions examples/nuxt3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"devDependencies": {
"@histoire/plugin-nuxt": "workspace:*",
"@histoire/plugin-vue": "workspace:*",
"@nuxtjs/tailwindcss": "^5.3.5",
"@nuxtjs/tailwindcss": "^6.8.0",
"cypress": "^10.11.0",
"histoire": "workspace:*",
"nuxt": "^3.6.5",
"nuxt": "^3.7.3",
"start-server-and-test": "^1.15.4",
"vue": "^3.3.4"
}
Expand Down
1 change: 1 addition & 0 deletions packages/histoire-plugin-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"dependencies": {
"@nuxt/kit": "^3.6.5",
"@rollup/plugin-replace": "^5.0.2",
"@vitejs/plugin-vue": "^4.2.3",
"@vitejs/plugin-vue-jsx": "^3.0.1",
"h3": "^1.7.1",
Expand Down
21 changes: 19 additions & 2 deletions packages/histoire-plugin-nuxt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fileURLToPath } from 'node:url'
import { join } from 'node:path'
import vuePlugin from '@vitejs/plugin-vue'
import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
import replace from '@rollup/plugin-replace'
import type { Plugin } from 'histoire'
import type { Nuxt } from '@nuxt/schema'
import type { UserConfig as ViteConfig } from 'vite'
Expand Down Expand Up @@ -40,13 +41,29 @@ export function HstNuxt (): Plugin {
},
middlewareMode: false,
},
define: viteConfig.define,
define: {
...viteConfig.define,
'process.server': false,
'process.client': true,
'process.browser': true,
'process.nitro': false,
'process.prerender': false,
},
resolve: {
alias: viteConfig.resolve.alias,
extensions: viteConfig.resolve.extensions,
dedupe: viteConfig.resolve.dedupe,
},
plugins,
plugins: [
...plugins,
replace({
values: {
'import.meta.server': 'false',
'import.meta.client': 'true',
},
preventAssignment: true,
}),
],
css: viteConfig.css,
publicDir: viteConfig.publicDir,
optimizeDeps: {
Expand Down
3 changes: 2 additions & 1 deletion packages/histoire-plugin-nuxt/src/runtime/app-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ export async function setupNuxtApp (publicConfig: PublicRuntimeConfig) {
win.__app = h3App

// @ts-ignore
await import('#app/entry')
const result = await import('#app/entry')
await result.default()
}
Loading

0 comments on commit d8bb144

Please sign in to comment.