8000 feat(webpack): angular 16.1 support (#10317) · NativeScript/NativeScript@dd10bfc · GitHub
[go: up one dir, main page]

Skip to content

Commit dd10bfc

Browse files
authored
feat(webpack): angular 16.1 support (#10317)
1 parent 42d22a2 commit dd10bfc

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ exports[`angular configuration for android 1`] = `
206206
use: [
207207
/* config.module.rule('angular-webpack-loader').use('webpack-loader') */
208208
{
209-
loader: '@angular-devkit/build-angular/src/babel/webpack-loader',
209+
loader: '<rootDir>/node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js',
210210
options: {
211211
aot: true
212212
}
@@ -632,7 +632,7 @@ exports[`angular configuration for ios 1`] = `
632632
use: [
633633
/* config.module.rule('angular-webpack-loader').use('webpack-loader') */
634634
{
635-
loader: '@angular-devkit/build-angular/src/babel/webpack-loader',
635+
loader: '<rootDir>/node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js',
636636
options: {
637637
aot: true
638638
}

packages/webpack5/jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ module.exports = {
1313
],
1414
globals: {
1515
__TEST__: true,
16-
}
16+
},
17+
resolver: '<rootDir>/scripts/resolver.js',
1718
};

packages/webpack5/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@
5454
"webpack-virtual-modules": "^0.4.0"
5555
},
5656
"devDependencies": {
57-
"@angular-devkit/build-angular": "^15.0.1",
57+
"@angular-devkit/build-angular": "^16.1.0",
5858
"@types/css": "0.0.33",
59-
"@types/jest": "29.4.0",
59+
"@types/jest": "29.5.2",
6060
"@types/loader-utils": "2.0.3",
6161
"@types/lodash.get": "4.4.7",
6262
"@types/micromatch": "4.0.2",
6363
"@types/sax": "1.2.4",
6464
"@types/terser-webpack-plugin": "5.2.0",
6565
"@types/webpack-virtual-modules": "0.1.1",
66-
"jest": "29.4.1",
66+
"jest": "29.5.0",
6767
"jest-matcher-utils": "29.4.1",
6868
"nativescript-vue-template-compiler": "2.9.3",
69-
"ts-jest": "29.0.5",
69+
"ts-jest": "29.1.0",
7070
"typescript": "~4.9.5"
7171
},
7272
"peerDependencies": {

packages/webpack5/scripts/resolver.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { relative, join } = require('path');
2+
3+
const packagesToMakeRelative = new Set([
4+
'@angular-devkit/build-angular/src/tools/babel/webpack-loader',
5+
'@angular-devkit/build-angular/src/babel/webpack-loader',
6+
]);
7+
8+
function resolver(path, options) {
9+
const defaultResolver = options.defaultResolver(path, options);
10+
if (typeof defaultResolver === 'string' && packagesToMakeRelative.has(path)) {
11+
return join('<rootDir>', relative(join(__dirname, '..'), defaultResolver));
12+
}
13+
return defaultResolver;
14+
}
15+
16+
module.exports = resolver;

packages/webpack5/src/configuration/angular.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
214214
.end()
215215
.before('angular')
216216
.use('webpack-loader')
217-
.loader('@angular-devkit/build-angular/src/babel/webpack-loader')
217+
.loader(getWebpackLoaderPath())
218218
.options(buildAngularOptions);
219219
} else {
220220
warnOnce(
@@ -334,3 +334,24 @@ function getBuildAngularMajorVersion() {
334334

335335
return null;
336336
}
337+
338+
function tryRequireResolve(path: string) {
339+
try {
340+
return require.resolve(path);
341+
} catch (err) {
342+
return null;
343+
}
344+
}
345+
346+
function getWebpackLoaderPath() {
347+
return (
348+
tryRequireResolve(
349+
'@angular-devkit/build-angular/src/babel/webpack-loader'
350+
) ||
351+
tryRequireResolve(
352+
'@angular-devkit/build-angular/src/tools/babel/webpack-loader'
353+
) ||
354+
// fallback to angular 16.1+
355+
'@angular-devkit/build-angular/src/tools/babel/webpack-loader'
356+
);
357+
}

0 commit comments

Comments
 (0)
0