diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap index 382128cad..bf7605ccd 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap @@ -108,6 +108,16 @@ exports[`angular configuration for android 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -233,6 +243,7 @@ exports[`angular configuration for android 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { @@ -337,6 +348,12 @@ exports[`angular configuration for android 1`] = ` function () { /* omitted long function */ } ] } + ), + /* config.plugin('AngularWebpackPlugin') */ + new AngularWebpackPlugin( + { + tsconfig: '__jest__/tsconfig.json' + } ) ], entry: { @@ -458,6 +475,16 @@ exports[`angular configuration for ios 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -583,6 +610,7 @@ exports[`angular configuration for ios 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { @@ -687,6 +715,12 @@ exports[`angular configuration for ios 1`] = ` function () { /* omitted long function */ } ] } + ), + /* config.plugin('AngularWebpackPlugin') */ + new AngularWebpackPlugin( + { + tsconfig: '__jest__/tsconfig.json' + } ) ], entry: { @@ -700,3 +734,26 @@ exports[`angular configuration for ios 1`] = ` } }" `; + +exports[`angular configuration loads polyfills.android.ts into the bundle entry if it exists 1`] = ` +Array [ + "__jest__/src/polyfills.android.ts", + "__jest__/src/app.js", + "@nativescript/core/ui/frame", + "@nativescript/core/ui/frame/activity", +] +`; + +exports[`angular configuration loads polyfills.ios.ts into the bundle entry if it exists 1`] = ` +Array [ + "__jest__/src/polyfills.ios.ts", + "__jest__/src/app.js", +] +`; + +exports[`angular configuration loads polyfills.ts into the bundle entry if it exists 1`] = ` +Array [ + "__jest__/src/polyfills.ts", + "__jest__/src/app.js", +] +`; diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap index d365dc75e..e8082333b 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap @@ -123,6 +123,16 @@ exports[`base configuration for android 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -180,6 +190,7 @@ exports[`base configuration for android 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { @@ -422,6 +433,16 @@ exports[`base configuration for ios 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -479,6 +500,7 @@ exports[`base configuration for ios 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap index 8dbf3f94f..3f7484158 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap @@ -123,6 +123,16 @@ exports[`javascript configuration for android 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -177,16 +187,6 @@ exports[`javascript configuration for android 1`] = ` } ] }, - /* config.module.rule('xml') */ - { - test: /\\\\.xml$/, - use: [ - /* config.module.rule('xml').use('xml-namespace-loader') */ - { - loader: 'xml-namespace-loader' - } - ] - }, /* config.module.rule('hmr-core') */ { test: /\\\\.js$/, @@ -207,6 +207,7 @@ exports[`javascript configuration for android 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { @@ -454,6 +455,16 @@ exports[`javascript configuration for ios 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -508,16 +519,6 @@ exports[`javascript configuration for ios 1`] = ` } ] }, - /* config.module.rule('xml') */ - { - test: /\\\\.xml$/, - use: [ - /* config.module.rule('xml').use('xml-namespace-loader') */ - { - loader: 'xml-namespace-loader' - } - ] - }, /* config.module.rule('hmr-core') */ { test: /\\\\.js$/, @@ -538,6 +539,7 @@ exports[`javascript configuration for ios 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap index bfd48d980..d81be1944 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap @@ -138,6 +138,16 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -195,6 +205,7 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { @@ -448,6 +459,16 @@ exports[`react configuration > android > base config 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -505,6 +526,7 @@ exports[`react configuration > android > base config 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { @@ -758,6 +780,16 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -815,6 +847,7 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { @@ -1069,6 +1102,16 @@ exports[`react configuration > ios > base config 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -1126,6 +1169,7 @@ exports[`react configuration > ios > base config 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap index d48d7a753..167912318 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap @@ -125,6 +125,16 @@ exports[`svelte configuration for android 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -205,6 +215,7 @@ exports[`svelte configuration for android 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { @@ -443,6 +454,16 @@ exports[`svelte configuration for ios 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -523,6 +544,7 @@ exports[`svelte configuration for ios 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap index eb7b64d61..a345c07c9 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap @@ -123,6 +123,16 @@ exports[`typescript configuration for android 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -177,16 +187,6 @@ exports[`typescript configuration for android 1`] = ` } ] }, - /* config.module.rule('xml') */ - { - test: /\\\\.xml$/, - use: [ - /* config.module.rule('xml').use('xml-namespace-loader') */ - { - loader: 'xml-namespace-loader' - } - ] - }, /* config.module.rule('hmr-core') */ { test: /\\\\.(js|ts)$/, @@ -207,6 +207,7 @@ exports[`typescript configuration for android 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { @@ -454,6 +455,16 @@ exports[`typescript configuration for ios 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -508,16 +519,6 @@ exports[`typescript configuration for ios 1`] = ` } ] }, - /* config.module.rule('xml') */ - { - test: /\\\\.xml$/, - use: [ - /* config.module.rule('xml').use('xml-namespace-loader') */ - { - loader: 'xml-namespace-loader' - } - ] - }, /* config.module.rule('hmr-core') */ { test: /\\\\.(js|ts)$/, @@ -538,6 +539,7 @@ exports[`typescript configuration for ios 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap index 78c760967..2eac51a40 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap @@ -129,6 +129,16 @@ exports[`vue configuration for android 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -204,6 +214,7 @@ exports[`vue configuration for android 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { @@ -454,6 +465,16 @@ exports[`vue configuration for ios 1`] = ` } ] }, + /* config.module.rule('xml') */ + { + test: /\\\\.xml$/, + use: [ + /* config.module.rule('xml').use('xml-namespace-loader') */ + { + loader: 'xml-namespace-loader' + } + ] + }, /* config.module.rule('css') */ { test: /\\\\.css$/, @@ -529,6 +550,7 @@ exports[`vue configuration for ios 1`] = ` ] }, optimization: { + runtimeChunk: 'single', splitChunks: { cacheGroups: { defaultVendor: { diff --git a/packages/webpack5/__tests__/configuration/angular.spec.ts b/packages/webpack5/__tests__/configuration/angular.spec.ts index a96630db1..8cab9190b 100644 --- a/packages/webpack5/__tests__/configuration/angular.spec.ts +++ b/packages/webpack5/__tests__/configuration/angular.spec.ts @@ -1,17 +1,20 @@ import Config from 'webpack-chain'; -import { resolve } from 'path'; -import { additionalCopyRules } from '../../src/helpers/copyRules'; import { default as angular } from '../../src/configuration/angular'; import { init } from '../../src'; jest.mock( '@ngtools/webpack', () => { + // in tests we mock both plugins so they both show up in the snapshot + // allowing us to verify the passed configuration is correct. class AngularCompilerPlugin {} + class AngularWebpackPlugin {} + return { AngularCompilerPlugin, + AngularWebpackPlugin, }; }, { virtual: true } @@ -20,6 +23,7 @@ jest.mock( describe('angular configuration', () => { const platforms = ['ios', 'android']; let fsExistsSyncSpy: jest.SpiedFunction; + let polyfillsPath: string | boolean = false; beforeAll(() => { const fs = require('fs'); @@ -30,6 +34,11 @@ describe('angular configuration', () => { if (path === '__jest__/tsconfig.json') { return true; } + + if (polyfillsPath && path === polyfillsPath) { + return true; + } + return original.call(fs, path); }); }); @@ -45,5 +54,27 @@ describe('angular configuration', () => { }); expect(angular(new Config()).toString()).toMatchSnapshot(); }); + + it(`loads polyfills.${platform}.ts into the bundle entry if it exists `, () => { + polyfillsPath = `__jest__/src/polyfills.${platform}.ts`; + + init({ + [platform]: true, + }); + expect(angular(new Config()).entry('bundle').values()).toMatchSnapshot(); + + polyfillsPath = false; + }); } + + it(`loads polyfills.ts into the bundle entry if it exists `, () => { + polyfillsPath = `__jest__/src/polyfills.ts`; + + init({ + ios: true, + }); + expect(angular(new Config()).entry('bundle').values()).toMatchSnapshot(); + + polyfillsPath = false; + }); }); diff --git a/packages/webpack5/src/helpers/virtualModules.ts b/packages/webpack5/src/helpers/virtualModules.ts index d02202bab..4e8a79b93 100644 --- a/packages/webpack5/src/helpers/virtualModules.ts +++ b/packages/webpack5/src/helpers/virtualModules.ts @@ -41,7 +41,8 @@ export function addVirtualModule( // AngularCompilerPlugin does not support virtual modules // https://github.com/sysgears/webpack-virtual-modules/issues/96 // This is only an issue on v11, which has experimental webpack 5 support - // AngularCompilerPlugin gets replaced by AngularWebpackPlugin on v12 and i + // AngularCompilerPlugin gets replaced by AngularWebpackPlugin on v12 + // todo: we can remove this special handling once we no longer support v11 if (config.plugins.has('AngularCompilerPlugin')) { const compatEntryPath = getProjectFilePath( join('node_modules', '.nativescript', `${name}`)