feat(webpack): angular 16.1 support (#10317)

This commit is contained in:
Eduardo Speroni
2023-06-21 11:24:41 -03:00
committed by GitHub
parent 42d22a2aa5
commit dd10bfccc2
5 changed files with 46 additions and 8 deletions

View File

@ -206,7 +206,7 @@ exports[`angular configuration for android 1`] = `
use: [
/* config.module.rule('angular-webpack-loader').use('webpack-loader') */
{
loader: '@angular-devkit/build-angular/src/babel/webpack-loader',
loader: '<rootDir>/node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js',
options: {
aot: true
}
@ -632,7 +632,7 @@ exports[`angular configuration for ios 1`] = `
use: [
/* config.module.rule('angular-webpack-loader').use('webpack-loader') */
{
loader: '@angular-devkit/build-angular/src/babel/webpack-loader',
loader: '<rootDir>/node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js',
options: {
aot: true
}

View File

@ -13,5 +13,6 @@ module.exports = {
],
globals: {
__TEST__: true,
}
},
resolver: '<rootDir>/scripts/resolver.js',
};

View File

@ -54,19 +54,19 @@
"webpack-virtual-modules": "^0.4.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.0.1",
"@angular-devkit/build-angular": "^16.1.0",
"@types/css": "0.0.33",
"@types/jest": "29.4.0",
"@types/jest": "29.5.2",
"@types/loader-utils": "2.0.3",
"@types/lodash.get": "4.4.7",
"@types/micromatch": "4.0.2",
"@types/sax": "1.2.4",
"@types/terser-webpack-plugin": "5.2.0",
"@types/webpack-virtual-modules": "0.1.1",
"jest": "29.4.1",
"jest": "29.5.0",
"jest-matcher-utils": "29.4.1",
"nativescript-vue-template-compiler": "2.9.3",
"ts-jest": "29.0.5",
"ts-jest": "29.1.0",
"typescript": "~4.9.5"
},
"peerDependencies": {

View File

@ -0,0 +1,16 @@
const { relative, join } = require('path');
const packagesToMakeRelative = new Set([
'@angular-devkit/build-angular/src/tools/babel/webpack-loader',
'@angular-devkit/build-angular/src/babel/webpack-loader',
]);
function resolver(path, options) {
const defaultResolver = options.defaultResolver(path, options);
if (typeof defaultResolver === 'string' && packagesToMakeRelative.has(path)) {
return join('<rootDir>', relative(join(__dirname, '..'), defaultResolver));
}
return defaultResolver;
}
module.exports = resolver;

View File

@ -214,7 +214,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
.end()
.before('angular')
.use('webpack-loader')
.loader('@angular-devkit/build-angular/src/babel/webpack-loader')
.loader(getWebpackLoaderPath())
.options(buildAngularOptions);
} else {
warnOnce(
@ -334,3 +334,24 @@ function getBuildAngularMajorVersion() {
return null;
}
function tryRequireResolve(path: string) {
try {
return require.resolve(path);
} catch (err) {
return null;
}
}
function getWebpackLoaderPath() {
return (
tryRequireResolve(
'@angular-devkit/build-angular/src/babel/webpack-loader'
) ||
tryRequireResolve(
'@angular-devkit/build-angular/src/tools/babel/webpack-loader'
) ||
// fallback to angular 16.1+
'@angular-devkit/build-angular/src/tools/babel/webpack-loader'
);
}