|
1 | 1 | const { RawSource } = require("webpack-sources");
|
2 | 2 | const { getPackageJson } = require("../projectHelpers");
|
3 | 3 | const { SNAPSHOT_ENTRY_NAME } = require("./NativeScriptSnapshotPlugin");
|
4 |
| - |
| 4 | +const path = require("path"); |
5 | 5 |
|
6 | 6 | exports.GenerateNativeScriptEntryPointsPlugin = (function () {
|
7 | 7 | const GenerationFailedError = "Unable to generate entry files.";
|
@@ -49,38 +49,42 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () {
|
49 | 49 | return;
|
50 | 50 | }
|
51 | 51 |
|
52 |
| - const requireDeps = |
53 |
| - entryPoint.chunks.map(chunk => { |
54 |
| - let requireChunkFiles = ""; |
55 |
| - if (chunk.name === entryPointName) { |
56 |
| - entryChunk = chunk; |
57 |
| - } else { |
58 |
| - chunk.files.forEach(fileName => { |
59 |
| - if (!this.isHMRFile(fileName)) { |
60 |
| - requireChunkFiles += `require("./${fileName}");`; |
61 |
| - } |
62 |
| - }); |
63 |
| - } |
64 |
| - |
65 |
| - return requireChunkFiles; |
66 |
| - }).join(""); |
| 52 | + const requiredFiles = []; |
| 53 | + entryPoint.chunks.forEach(chunk => { |
| 54 | + if (chunk.name === entryPointName) { |
| 55 | + entryChunk = chunk; |
| 56 | + } else { |
| 57 | + chunk.files.forEach(fileName => { |
| 58 | + if (!this.isHMRFile(fileName)) { |
| 59 | + requiredFiles.push(fileName); |
| 60 | + } |
| 61 | + }); |
| 62 | + } |
| 63 | + }); |
67 | 64 |
|
68 | 65 | if (!entryChunk) {
|
69 | 66 | throw new Error(`${GenerationFailedError} Entry chunk not found for entry "${entryPointName}".`);
|
70 | 67 | }
|
71 | 68 |
|
72 |
| - entryChunk.files.forEach(fileName => { |
73 |
| - if (!compilation.assets[fileName]) { |
74 |
| - throw new Error(`${GenerationFailedError} File "${fileName}" not found for entry "${entryPointName}".`); |
| 69 | + entryChunk.files.forEach(filePath => { |
| 70 | + if (!compilation.assets[filePath]) { |
| 71 | + throw new Error(`${GenerationFailedError} File "${filePath}" not found for entry "${entryPointName}".`); |
75 | 72 | }
|
76 | 73 |
|
77 |
| - if (!this.isHMRFile(fileName)) { |
78 |
| - const currentEntryFileContent = compilation.assets[fileName].source(); |
79 |
| - compilation.assets[fileName] = new RawSource(`${requireDeps}${currentEntryFileContent}`); |
| 74 | + if (!this.isHMRFile(filePath)) { |
| 75 | + const currFileDirRelativePath = path.dirname(filePath); |
| 76 | + const pathToRootFromCurrFile = path.relative(currFileDirRelativePath, "."); |
| 77 | + |
| 78 | + const requireDeps = requiredFiles.map(depPath => { |
| 79 | + const depRelativePath = path.join(pathToRootFromCurrFile, depPath); |
| 80 | + |
| 81 | + return `require("./${depRelativePath}");`; |
| 82 | + }).join(""); |
| 83 | + const currentEntryFileContent = compilation.assets[filePath].source(); |
| 84 | + compilation.assets[filePath] = new RawSource(`${requireDeps}${currentEntryFileContent}`); |
80 | 85 | }
|
81 | 86 | });
|
82 | 87 | }
|
83 |
| - |
84 | 88 | GenerateNativeScriptEntryPointsPlugin.prototype.addAsset = function (compilation, name, content) {
|
85 | 89 | if (this.files[name] !== content) {
|
86 | 90 | this.files[name] = content;
|
|
0 commit comments