fix(webpack): add virtualEntry before main entry

fixes running with the JSC runtime, fixes #9469
This commit is contained in:
rigor789
2021-08-03 15:41:14 +02:00
parent 00b7c7b135
commit 5a3a35d376
3 changed files with 36 additions and 6 deletions

View File

@ -2,6 +2,7 @@ import Config from 'webpack-chain';
import { getEntryPath, getEntryDirPath } from '../helpers/platform'; import { getEntryPath, getEntryDirPath } from '../helpers/platform';
import { addVirtualEntry } from '../helpers/virtualModules'; import { addVirtualEntry } from '../helpers/virtualModules';
import { chainedSetAddAfter } from '../helpers/chain';
import { env as _env, IWebpackEnv } from '../index'; import { env as _env, IWebpackEnv } from '../index';
import base from './base'; import base from './base';
@ -21,9 +22,11 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
` `
); );
config.entry('bundle').add(virtualEntryPath); chainedSetAddAfter(
config.entry('bundle'),
// config.resolve.extensions.add('.xml'); '@nativescript/core/globals/index.js',
virtualEntryPath
);
// set up core HMR // set up core HMR
config.module config.module

View File

@ -2,6 +2,7 @@ import Config from 'webpack-chain';
import { getEntryDirPath, getEntryPath } from '../helpers/platform'; import { getEntryDirPath, getEntryPath } from '../helpers/platform';
import { addVirtualEntry } from '../helpers/virtualModules'; import { addVirtualEntry } from '../helpers/virtualModules';
import { chainedSetAddAfter } from '../helpers/chain';
import { env as _env, IWebpackEnv } from '../index'; import { env as _env, IWebpackEnv } from '../index';
import base from './base'; import base from './base';
@ -21,9 +22,11 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
` `
); );
config.entry('bundle').add(virtualEntryPath); chainedSetAddAfter(
config.entry('bundle'),
// config.resolve.extensions.add('.xml'); '@nativescript/core/globals/index.js',
virtualEntryPath
);
// set up core HMR // set up core HMR
config.module config.module

View File

@ -0,0 +1,24 @@
import { ChainedSet } from 'webpack-chain';
/**
* Helper to insert values after a specific item in a ChainedSet.
*
* @param chainedSet
* @param after
* @param itemToAdd
*/
export function chainedSetAddAfter(
chainedSet: ChainedSet<any>,
after: any,
itemToAdd: any
) {
const values = chainedSet.values();
if (values.includes(after)) {
values.splice(values.indexOf(after) + 1, 0, itemToAdd);
} else {
values.push(itemToAdd);
}
chainedSet.clear().merge(values);
}