feat(webpack5): support for angular polyfills.ts

This commit is contained in:
Eduardo Speroni
2021-05-28 19:03:01 -03:00
parent b8e6bfb7c0
commit 7322ead729

View File

@ -1,8 +1,12 @@
import Config from 'webpack-chain';
import { existsSync } from 'fs';
import { extname } from 'path';
import { extname, join } from 'path';
import { getEntryPath, getPlatformName } from '../helpers/platform';
import {
getEntryDirPath,
getEntryPath,
getPlatformName,
} from '../helpers/platform';
import { getProjectFilePath } from '../helpers/project';
import { env as _env, IWebpackEnv } from '../index';
import base from './base';
@ -128,6 +132,22 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
]);
}
const getPolyfillPath = (platform?: string) =>
join(getEntryDirPath(), `polyfills${platform ? '.' + platform : ''}.ts`);
const polyfillsPath = getPolyfillPath();
const polyfillsPathResolved = [
polyfillsPath,
getPolyfillPath('android'),
getPolyfillPath('ios'),
];
if (polyfillsPathResolved.find(existsSync)) {
let entries = config.entry('bundle').values();
entries = entries.map((v) =>
v === '@nativescript/core/globals/index.js' ? polyfillsPath : v
);
config.entry('bundle').clear().merge(entries);
}
// Filter common undesirable warnings
config.set(
'ignoreWarnings',