From 358cfb3a297fca982aaaf8268cf99496df12802d Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Thu, 27 Apr 2017 12:41:02 -0700 Subject: [PATCH] Make dynamic import support to work with HMR. --- server/build/plugins/dynamic-chunks-plugin.js | 6 ++++++ server/index.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/server/build/plugins/dynamic-chunks-plugin.js b/server/build/plugins/dynamic-chunks-plugin.js index 6907b551..8f00a956 100644 --- a/server/build/plugins/dynamic-chunks-plugin.js +++ b/server/build/plugins/dynamic-chunks-plugin.js @@ -26,6 +26,12 @@ export default class PagesPlugin { source: () => newContent, size: () => newContent.length } + + // This is to support, webpack dynamic import support with HMR + compilation.assets[`chunks/${chunk.id}`] = { + source: () => newContent, + size: () => newContent.length + } }) callback() }) diff --git a/server/index.js b/server/index.js index 568baae2..e03c09d6 100644 --- a/server/index.js +++ b/server/index.js @@ -106,6 +106,12 @@ export default class Server { await this.serveStatic(req, res, p) }, + // This is to support, webpack dynamic import support with HMR + '/_next/webpack/:id': async (req, res, params) => { + const p = join(this.dir, '.next', 'chunks', params.id) + await this.serveStatic(req, res, p) + }, + '/_next/:hash/manifest.js': async (req, res, params) => { this.handleBuildHash('manifest.js', params.hash, res) const p = join(this.dir, `${this.dist}/manifest.js`)