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

Commit fe4ffd9

Browse files
committed
fix: support platform specific entry modules
1 parent 160b4a5 commit fe4ffd9

8 files changed

+20
-13
lines changed

index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,21 @@ exports.getAotEntryModule = function (appDirectory) {
2525
return aotEntry;
2626
}
2727

28-
exports.getEntryModule = function (appDirectory) {
28+
exports.getEntryModule = function (appDirectory, platform) {
2929
verifyEntryModuleDirectory(appDirectory);
3030

3131
const entry = getPackageJsonEntry(appDirectory);
3232

3333
const tsEntryPath = path.resolve(appDirectory, `${entry}.ts`);
3434
const jsEntryPath = path.resolve(appDirectory, `${entry}.js`);
35-
if (!existsSync(tsEntryPath) && !existsSync(jsEntryPath)) {
35+
let entryExists = existsSync(tsEntryPath) || existsSync(jsEntryPath);
36+
if (!entryExists && platform) {
37+
const platformTsEntryPath = path.resolve(appDirectory, `${entry}.${platform}.ts`);
38+
const platformJsEntryPath = path.resolve(appDirectory, `${entry}.${platform}.js`);
39+
entryExists = existsSync(platformTsEntryPath) || existsSync(platformJsEntryPath);
40+
}
41+
42+
if (!entryExists) {
3643
throw new Error(`The entry module ${entry} specified in ` +
3744
`${appDirectory}/package.json doesn't exist!`)
3845
}

plugins/NativeScriptAngularCompilerPlugin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parse, sep } from "path";
1+
import { parse, join } from "path";
22
import { AngularCompilerPlugin } from "@ngtools/webpack";
33

44
export function getAngularCompilerPlugin(platform: string): any {
@@ -14,7 +14,7 @@ export function getAngularCompilerPlugin(platform: string): any {
1414
try {
1515
if (platform) {
1616
const parsed = parse(file);
17-
const platformFile = parsed.dir + sep + parsed.name + "." + platform + parsed.ext;
17+
const platformFile = join(parsed.dir, `${parsed.name}.${platform}${parsed.ext}`);
1818
return super.getCompiledFile(platformFile);;
1919
}
2020
}

plugins/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ module.exports = Object.assign({},
33
require("./NativeScriptSnapshotPlugin"),
44
require("./PlatformSuffixPlugin"),
55
require("./PlatformFSPlugin"),
6-
require("./WatchStateLoggerPlugin"),
7-
require("./NativeScriptAngularCompilerPlugin")
6+
require("./WatchStateLoggerPlugin")
87
);

templates/webpack.angular.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const CopyWebpackPlugin = require("copy-webpack-plugin");
1212
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
1313
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
1414
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
15+
const { getAngularCompilerPlugin } = require("nativescript-dev-webpack/plugins/NativeScriptAngularCompilerPlugin");
1516
const hashSalt = Date.now().toString();
1617

1718
module.exports = env => {
@@ -26,7 +27,7 @@ module.exports = env => {
2627
throw new Error("You need to provide a target platform!");
2728
}
2829

29-
const AngularCompilerPlugin = nsWebpack.getAngularCompilerPlugin(platform);
30+
const AngularCompilerPlugin = getAngularCompilerPlugin(platform);
3031
const projectRoot = __dirname;
3132

3233
// Default destination inside platforms/<platform>/...
@@ -54,7 +55,7 @@ module.exports = env => {
5455
const appFullPath = resolve(projectRoot, appPath);
5556
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
5657
const tsConfigName = "tsconfig.tns.json";
57-
const entryModule = `${nsWebpack.getEntryModule(appFullPath)}.ts`;
58+
const entryModule = `${nsWebpack.getEntryModule(appFullPath, platform)}.ts`;
5859
const entryPath = `.${sep}${entryModule}`;
5960
const entries = { bundle: entryPath };
6061
if (platform === "ios") {

templates/webpack.config.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ const nativeScriptDevWebpack = {
2222
getEntryModule: () => 'EntryModule',
2323
getResolver: () => null,
2424
getEntryPathRegExp: () => null,
25-
getConvertedExternals: nsWebpackIndex.getConvertedExternals,
26-
getAngularCompilerPlugin: () => AngularCompilerStub
25+
getConvertedExternals: nsWebpackIndex.getConvertedExternals
2726
};
2827

2928
const emptyObject = {};
@@ -37,6 +36,7 @@ const webpackConfigAngular = proxyquire('./webpack.angular', {
3736
'nativescript-dev-webpack/transformers/ns-replace-lazy-loader': { nsReplaceLazyLoader: () => { return FakeLazyTransformerFlag } },
3837
'nativescript-dev-webpack/transformers/ns-support-hmr-ng': { nsSupportHmrNg: () => { return FakeHmrTransformerFlag } },
3938
'nativescript-dev-webpack/utils/ast-utils': { getMainModulePath: () => { return "fakePath"; } },
39+
'nativescript-dev-webpack/plugins/NativeScriptAngularCompilerPlugin': { getAngularCompilerPlugin: () => { return AngularCompilerStub; } },
4040
'@ngtools/webpack': {
4141
AngularCompilerPlugin: AngularCompilerStub
4242
}

templates/webpack.javascript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = env => {
4949
const appFullPath = resolve(projectRoot, appPath);
5050
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
5151

52-
const entryModule = nsWebpack.getEntryModule(appFullPath);
52+
const entryModule = nsWebpack.getEntryModule(appFullPath, platform);
5353
const entryPath = `.${sep}${entryModule}.js`;
5454
const entries = { bundle: entryPath };
5555
if (platform === "ios") {

templates/webpack.typescript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = env => {
4949
const appFullPath = resolve(projectRoot, appPath);
5050
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
5151

52-
const entryModule = nsWebpack.getEntryModule(appFullPath);
52+
const entryModule = nsWebpack.getEntryModule(appFullPath, platform);
5353
const entryPath = `.${sep}${entryModule}.ts`;
5454
const entries = { bundle: entryPath };
5555
if (platform === "ios") {

templates/webpack.vue.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = env => {
5656
const appFullPath = resolve(projectRoot, appPath);
5757
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
5858

59-
const entryModule = nsWebpack.getEntryModule(appFullPath);
59+
const entryModule = nsWebpack.getEntryModule(appFullPath, platform);
6060
const entryPath = `.${sep}${entryModule}`;
6161
const entries = { bundle: entryPath };
6262
if (platform === "ios") {

0 commit comments

Comments
 (0)