From 2d4e10b645f982034a0e69a2d3ba338af9c0a255 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 9 Jul 2020 15:06:23 +0100 Subject: [PATCH] fix: create `static-json` dir at correct point in generate lifecycle Fixes error "Error: ENOENT: no such file or directory, mkdir '.nuxt/static-json'" --- package.json | 5 +++-- src/index.ts | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 7d5abaf7..5f8f657f 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,10 @@ "watch": "yarn compile -w", "clean": "rm -rf lib/*", "compile": "rollup -c", + "clean:fixture": "rm -rf dist/ test/fixture/.nuxt", "fixture": "yarn nuxt-run dev", - "fixture:prod": "rm -rf .nuxt && yarn nuxt-run build && yarn nuxt-run start", - "fixture:generate:export": "export GENERATE=true && rm -rf .nuxt && yarn nuxt-run build && PORT=6000 yarn nuxt-run export", + "fixture:prod": "yarn clean:fixture && yarn nuxt-run build && yarn nuxt-run start", + "fixture:generate:export": "yarn clean:fixture && export GENERATE=true && yarn nuxt-run build && PORT=6000 yarn nuxt-run export", "fixture:generate": "yarn fixture:generate:export && yarn http-server -s -p 5000 dist", "lint": "run-s lint:all:*", "lint:all:eslint": "yarn lint:eslint --ext .js,.ts,.vue .", diff --git a/src/index.ts b/src/index.ts index 2c87f1e3..8ff992f4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { resolve, join } from 'path' -import { rmdirSync, readdirSync, copyFileSync, existsSync, mkdirSync } from 'fs' +import { readdirSync, copyFileSync, existsSync, mkdirpSync } from 'fs-extra' import type { Module } from '@nuxt/types' @@ -28,9 +28,8 @@ const compositionApiModule: Module = function () { const staticPath = join(this.options.buildDir || '', 'static-json') - this.nuxt.hook('generate:before', () => { - if (existsSync(staticPath)) rmdirSync(staticPath) - mkdirSync(staticPath) + this.nuxt.hook('generate:route', () => { + mkdirpSync(staticPath) }) this.nuxt.hook('generate:done', async (generator: any) => {