mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
refactor: angular polyfill loading
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
|
import { extname, resolve } from 'path';
|
||||||
import Config from 'webpack-chain';
|
import Config from 'webpack-chain';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { extname, join } from 'path';
|
|
||||||
|
|
||||||
|
import { getProjectFilePath } from '../helpers/project';
|
||||||
|
import { env as _env, IWebpackEnv } from '../index';
|
||||||
import {
|
import {
|
||||||
getEntryDirPath,
|
getEntryDirPath,
|
||||||
getEntryPath,
|
getEntryPath,
|
||||||
getPlatformName,
|
getPlatformName,
|
||||||
} from '../helpers/platform';
|
} from '../helpers/platform';
|
||||||
import { getProjectFilePath } from '../helpers/project';
|
|
||||||
import { env as _env, IWebpackEnv } from '../index';
|
|
||||||
import base from './base';
|
import base from './base';
|
||||||
|
|
||||||
export default function (config: Config, env: IWebpackEnv = _env): Config {
|
export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||||
@@ -132,20 +132,27 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPolyfillPath = (platform?: string) =>
|
// look for platform specific polyfills first
|
||||||
join(getEntryDirPath(), `polyfills${platform ? '.' + platform : ''}.ts`);
|
// falling back to independent polyfills
|
||||||
const polyfillsPath = getPolyfillPath();
|
const polyfillsPath = [
|
||||||
const polyfillsPathResolved = [
|
resolve(getEntryDirPath(), `polyfills.${getPlatformName()}.ts`),
|
||||||
polyfillsPath,
|
resolve(getEntryDirPath(), `polyfills.ts`),
|
||||||
getPolyfillPath('android'),
|
].find((path) => existsSync(path));
|
||||||
getPolyfillPath('ios'),
|
|
||||||
];
|
if (polyfillsPath) {
|
||||||
if (polyfillsPathResolved.find(existsSync)) {
|
const paths = config.entry('bundle').values();
|
||||||
let entries = config.entry('bundle').values();
|
|
||||||
entries = entries.map((v) =>
|
// replace globals with the polyfills file which
|
||||||
v === '@nativescript/core/globals/index.js' ? polyfillsPath : v
|
// should handle loading the correct globals
|
||||||
);
|
// and any additional polyfills required.
|
||||||
config.entry('bundle').clear().merge(entries);
|
if (paths.includes('@nativescript/core/globals/index.js')) {
|
||||||
|
paths[
|
||||||
|
paths.indexOf('@nativescript/core/globals/index.js')
|
||||||
|
] = polyfillsPath;
|
||||||
|
|
||||||
|
// replace paths with the update paths
|
||||||
|
config.entry('bundle').clear().merge(paths);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter common undesirable warnings
|
// Filter common undesirable warnings
|
||||||
|
|||||||
Reference in New Issue
Block a user