Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 48b26f4

Browse files
author
Dimitar Tachev
authored
Merge pull request #922 from NativeScript/tachev/fix-custom-output
fix: handle entry points with custom output filename
2 parents 31f6240 + 3aef461 commit 48b26f4

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

plugins/GenerateNativeScriptEntryPointsPlugin.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
const { RawSource } = require("webpack-sources");
22
const { getPackageJson } = require("../projectHelpers");
3-
const { SNAPSHOT_ENTRY_MODULE } = require("./NativeScriptSnapshotPlugin");
3+
const { SNAPSHOT_ENTRY_NAME } = require("./NativeScriptSnapshotPlugin");
4+
45

56
exports.GenerateNativeScriptEntryPointsPlugin = (function () {
7+
const GenerationFailedError = "Unable to generate entry files.";
8+
69
function GenerateNativeScriptEntryPointsPlugin(appEntryName) {
710
this.appEntryName = appEntryName;
811
this.files = {};
@@ -39,26 +42,39 @@ exports.GenerateNativeScriptEntryPointsPlugin = (function () {
3942
}
4043

4144
GenerateNativeScriptEntryPointsPlugin.prototype.generateEntryFile = function (compilation, entryPoint) {
42-
const entryPointFileName = `${entryPoint.options.name}.js`;
43-
if (entryPointFileName === SNAPSHOT_ENTRY_MODULE) {
45+
const entryPointName = entryPoint.options.name;
46+
let entryChunk;
47+
if (entryPointName === SNAPSHOT_ENTRY_NAME) {
4448
// Do not require the snapshot entry dependencies as the snapshot will fail.
4549
return;
4650
}
4751

4852
const requireDeps =
4953
entryPoint.chunks.map(chunk => {
5054
let requireChunkFiles = "";
51-
chunk.files.forEach(fileName => {
52-
if (fileName !== entryPointFileName) {
55+
if (chunk.name === entryPointName) {
56+
entryChunk = chunk;
57+
} else {
58+
chunk.files.forEach(fileName => {
5359
requireChunkFiles += `require("./${fileName}");`;
54-
}
55-
});
60+
});
61+
}
5662

5763
return requireChunkFiles;
58-
}).join("\n");
64+
}).join("");
65+
66+
if (!entryChunk) {
67+
throw new Error(`${GenerationFailedError} Entry chunk not found for entry "${entryPointName}".`);
68+
}
69+
70+
entryChunk.files.forEach(fileName => {
71+
if (!compilation.assets[fileName]) {
72+
throw new Error(`${GenerationFailedError} File "${fileName}" not found for entry "${entryPointName}".`);
73+
}
5974

60-
const currentEntryPointContent = compilation.assets[entryPointFileName].source();
61-
compilation.assets[entryPointFileName] = new RawSource(`${requireDeps}${currentEntryPointContent}`);
75+
const currentEntryFileContent = compilation.assets[fileName].source();
76+
compilation.assets[fileName] = new RawSource(`${requireDeps}${currentEntryFileContent}`);
77+
});
6278
}
6379

6480
GenerateNativeScriptEntryPointsPlugin.prototype.addAsset = function (compilation, name, content) {

plugins/NativeScriptSnapshotPlugin/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const schema = require("./options.json");
1212

1313
const SNAPSHOT_ENTRY_NAME = "snapshot-entry";
1414
const SNAPSHOT_ENTRY_MODULE = `${SNAPSHOT_ENTRY_NAME}.js`;
15-
exports.SNAPSHOT_ENTRY_MODULE = SNAPSHOT_ENTRY_MODULE;
15+
exports.SNAPSHOT_ENTRY_NAME = SNAPSHOT_ENTRY_NAME;
1616

1717
exports.NativeScriptSnapshotPlugin = (function () {
1818
function NativeScriptSnapshotPlugin(options) {

0 commit comments

Comments
 (0)