From 8298f955bf80eb44090cfb7b56070dc7e1a50aa8 Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Tue, 13 Oct 2020 20:47:06 +0200 Subject: [PATCH] fix: serve static webpack assets from disk in dev mode (fixes #373) --- lib/module.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/module.js b/lib/module.js index 01c9318d..c53cbd51 100755 --- a/lib/module.js +++ b/lib/module.js @@ -1,3 +1,6 @@ +const { resolve } = require('path') +const serveStatic = require('serve-static') + module.exports = async function nuxtPWA (moduleOptions) { const { nuxt } = this const moduleContainer = this // TODO: remove dependency when module-utils @@ -41,6 +44,15 @@ module.exports = async function nuxtPWA (moduleOptions) { } await require(`./${name}/module.js`)(nuxt, pwa, moduleContainer) } + + // Serve dist from disk + if (nuxt.options.dev) { + const clientDir = resolve(nuxt.options.buildDir, 'dist/client') + nuxt.options.serverMiddleware.push({ + path: nuxt.options.build.publicPath, + handler: serveStatic(clientDir) + }) + } } module.exports.meta = require('../package.json')