From 8f99c4dbaf4b3a433ff9f2b8d28486b2c9dc5307 Mon Sep 17 00:00:00 2001 From: Dawid Winiarczyk Date: Wed, 26 Jun 2019 07:55:32 +0200 Subject: [PATCH] Fix: Lazy loaded chunk has appended define externals on the begining (#25) --- lib/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index b92edb5..6ebd110 100644 --- a/lib/index.js +++ b/lib/index.js @@ -44,11 +44,18 @@ class MicroservicesWebpackPlugin { return {[fileName]: compilation.assets[fileName]}; } + const source = compilation.assets[fileName].source(); + const supportAmdOnly = 'define('; + + if (!source.startsWith(supportAmdOnly)) { + return {[fileName]: compilation.assets[fileName]}; + } + const value = [ this.modules .map(({ cdn, name }) => `define('${name}', ['${cdn}'], function(v) {return v;})`) .join('\n'), - compilation.assets[fileName].source() + source ].join('\n'); return {[fileName]: new RawSource(value)};