mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
fix(webpack): exclude other platforms from require.context (#9686)
fixes #9682
This commit is contained in:
@ -22,8 +22,9 @@ import { env as _env, IWebpackEnv } from '../index';
|
||||
import { getValue } from '../helpers/config';
|
||||
import { getIPS } from '../helpers/host';
|
||||
import {
|
||||
getPlatformName,
|
||||
getAvailablePlatforms,
|
||||
getAbsoluteDistPath,
|
||||
getPlatformName,
|
||||
getEntryDirPath,
|
||||
getEntryPath,
|
||||
} from '../helpers/platform';
|
||||
@ -365,6 +366,18 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
.plugin('ContextExclusionPlugin|App_Resources')
|
||||
.use(ContextExclusionPlugin, [new RegExp(`(.*)App_Resources(.*)`)]);
|
||||
|
||||
// Makes sure that require.context will never include code from
|
||||
// another platform (ie .android.ts when building for ios)
|
||||
const otherPlatformsRE = getAvailablePlatforms()
|
||||
.filter((platform) => platform !== getPlatformName())
|
||||
.join('|');
|
||||
|
||||
config
|
||||
.plugin('ContextExclusionPlugin|Other_Platforms')
|
||||
.use(ContextExclusionPlugin, [
|
||||
new RegExp(`\\.(${otherPlatformsRE})\\.(\\w+)$`),
|
||||
]);
|
||||
|
||||
// Filter common undesirable warnings
|
||||
config.set(
|
||||
'ignoreWarnings',
|
||||
|
@ -40,6 +40,13 @@ export function getPlatform(): INativeScriptPlatform {
|
||||
return platforms[getPlatformName()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to get all registered/available platforms
|
||||
*/
|
||||
export function getAvailablePlatforms(): string[] {
|
||||
return Object.keys(platforms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to get the currently targeted platform name
|
||||
*/
|
||||
@ -61,7 +68,7 @@ export function getPlatformName(): Platform {
|
||||
throw error(`
|
||||
Invalid platform: ${env.platform}
|
||||
|
||||
Valid platforms: ${Object.keys(platforms).join(', ')}
|
||||
Valid platforms: ${getAvailablePlatforms().join(', ')}
|
||||
`);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user