|
1 | 1 | const { RawSource } = require("webpack-sources"); |
2 | 2 | const { getPackageJson } = require("../projectHelpers"); |
3 | | -const { SNAPSHOT_ENTRY_MODULE } = require("./NativeScriptSnapshotPlugin"); |
| 3 | +const { SNAPSHOT_ENTRY_NAME } = require("./NativeScriptSnapshotPlugin"); |
4 | 4 |
|
5 | 5 | exports.GenerateNativeScriptEntryPointsPlugin = (function () { |
6 | 6 | function GenerateNativeScriptEntryPointsPlugin(appEntryName) { |
@@ -39,26 +39,33 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () { |
39 | 39 | } |
40 | 40 |
|
41 | 41 | GenerateNativeScriptEntryPointsPlugin.prototype.generateEntryFile = function (compilation, entryPoint) { |
42 | | - const entryPointFileName = `${entryPoint.options.name}.js`; |
43 | | - if (entryPointFileName === SNAPSHOT_ENTRY_MODULE) { |
| 42 | + const entryPointName = entryPoint.options.name; |
| 43 | + let entryChunk; |
| 44 | + if (entryPointName === SNAPSHOT_ENTRY_NAME) { |
44 | 45 | // Do not require the snapshot entry dependencies as the snapshot will fail. |
45 | 46 | return; |
46 | 47 | } |
47 | 48 |
|
48 | 49 | const requireDeps = |
49 | 50 | entryPoint.chunks.map(chunk => { |
50 | 51 | let requireChunkFiles = ""; |
51 | | - chunk.files.forEach(fileName => { |
52 | | - if (fileName !== entryPointFileName) { |
| 52 | + if (chunk.name === entryPointName) { |
| 53 | + entryChunk = chunk; |
| 54 | + } else { |
| 55 | + chunk.files.forEach(fileName => { |
53 | 56 | requireChunkFiles += `require("./${fileName}");`; |
54 | | - } |
55 | | - }); |
| 57 | + }); |
| 58 | + } |
56 | 59 |
|
57 | 60 | return requireChunkFiles; |
58 | 61 | }).join("\n"); |
59 | 62 |
|
60 | | - const currentEntryPointContent = compilation.assets[entryPointFileName].source(); |
61 | | - compilation.assets[entryPointFileName] = new RawSource(`${requireDeps}${currentEntryPointContent}`); |
| 63 | + if (entryChunk) { |
| 64 | + entryChunk.files.forEach(fileName => { |
| 65 | + const currentEntryFileContent = compilation.assets[fileName].source(); |
| 66 | + compilation.assets[fileName] = new RawSource(`${requireDeps}${currentEntryFileContent}`); |
| 67 | + }); |
| 68 | + } |
62 | 69 | } |
63 | 70 |
|
64 | 71 | GenerateNativeScriptEntryPointsPlugin.prototype.addAsset = function (compilation, name, content) { |
|
0 commit comments