From 2d01df9369ddc213c71a8573a21e1b25cac87e63 Mon Sep 17 00:00:00 2001 From: Kristian Dimitrov Date: Mon, 18 Nov 2019 13:59:57 +0200 Subject: [PATCH] fix: bundle emitted on save without changes When there are no changes (timestamps are not modified) the chunk is taken from the cache. The cached asset object has the property existsAt set and this will prevent the emit of that chunk - https://github.com/webpack/webpack/blob/4056506488c1e071dfc9a0127daa61bf531170bf/lib/Compiler.js#L326. However when we replace the whole asset, the flag is no longer set and the chunk is emmited every time. --- plugins/GenerateNativeScriptEntryPointsPlugin.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/GenerateNativeScriptEntryPointsPlugin.js b/plugins/GenerateNativeScriptEntryPointsPlugin.js index 9417be22..6f7177c3 100644 --- a/plugins/GenerateNativeScriptEntryPointsPlugin.js +++ b/plugins/GenerateNativeScriptEntryPointsPlugin.js @@ -1,5 +1,5 @@ const { convertToUnixPath } = require("../lib/utils"); -const { RawSource } = require("webpack-sources"); +const { RawSource, ConcatSource } = require("webpack-sources"); const { getPackageJson } = require("../projectHelpers"); const { SNAPSHOT_ENTRY_NAME } = require("./NativeScriptSnapshotPlugin"); const path = require("path"); @@ -83,7 +83,12 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () { return `require("./${depRelativePathUnix}");`; }).join(""); const currentEntryFileContent = compilation.assets[filePath].source(); - compilation.assets[filePath] = new RawSource(`${requireDeps}${currentEntryFileContent}`); + + if(compilation.assets[filePath] instanceof ConcatSource) { + compilation.assets[filePath].children.unshift(`${requireDeps}`); + } else { + compilation.assets[filePath] = new RawSource(`${requireDeps}${currentEntryFileContent}`); + } } }); }