mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 18:12:09 +08:00
fix(webpack): exclude other platforms from require.context (#9686)
fixes #9682
This commit is contained in:
@ -331,6 +331,10 @@ exports[`angular configuration for android 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@ -748,6 +752,10 @@ exports[`angular configuration for ios 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
@ -242,6 +242,10 @@ exports[`base configuration for android 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@ -556,6 +560,10 @@ exports[`base configuration for ios 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
@ -242,6 +242,10 @@ exports[`javascript configuration for android 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@ -565,6 +569,10 @@ exports[`javascript configuration for ios 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
@ -264,6 +264,10 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@ -589,6 +593,10 @@ exports[`react configuration > android > base config 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@ -921,6 +929,10 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@ -1247,6 +1259,10 @@ exports[`react configuration > ios > base config 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
@ -269,6 +269,10 @@ exports[`svelte configuration for android 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@ -604,6 +608,10 @@ exports[`svelte configuration for ios 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
@ -242,6 +242,10 @@ exports[`typescript configuration for android 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@ -565,6 +569,10 @@ exports[`typescript configuration for ios 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
@ -282,6 +282,10 @@ exports[`vue configuration for android 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@ -630,6 +634,10 @@ exports[`vue configuration for ios 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
@ -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