mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
fix(webpack): support angular 15.x (#10106)
This commit is contained in:
@ -1,5 +1,12 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`angular configuration @angular-devkit/build-angular backwards compatible sets scriptTarget for version <15 1`] = `
|
||||||
|
{
|
||||||
|
"aot": true,
|
||||||
|
"scriptTarget": 99,
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`angular configuration for android 1`] = `
|
exports[`angular configuration for android 1`] = `
|
||||||
"{
|
"{
|
||||||
mode: 'development',
|
mode: 'development',
|
||||||
@ -201,7 +208,6 @@ exports[`angular configuration for android 1`] = `
|
|||||||
{
|
{
|
||||||
loader: '@angular-devkit/build-angular/src/babel/webpack-loader',
|
loader: '@angular-devkit/build-angular/src/babel/webpack-loader',
|
||||||
options: {
|
options: {
|
||||||
scriptTarget: 99,
|
|
||||||
aot: true
|
aot: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -625,7 +631,6 @@ exports[`angular configuration for ios 1`] = `
|
|||||||
{
|
{
|
||||||
loader: '@angular-devkit/build-angular/src/babel/webpack-loader',
|
loader: '@angular-devkit/build-angular/src/babel/webpack-loader',
|
||||||
options: {
|
options: {
|
||||||
scriptTarget: 99,
|
|
||||||
aot: true
|
aot: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,4 +77,26 @@ describe('angular configuration', () => {
|
|||||||
|
|
||||||
polyfillsPath = false;
|
polyfillsPath = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('@angular-devkit/build-angular backwards compatible', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
jest.mock('@angular-devkit/build-angular/package.json', () => ({
|
||||||
|
version: '14.0.0',
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
jest.unmock('@angular-devkit/build-angular/package.json');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets scriptTarget for version <15', () => {
|
||||||
|
const config = angular(new Config());
|
||||||
|
expect(
|
||||||
|
config.module
|
||||||
|
.rule('angular-webpack-loader')
|
||||||
|
.use('webpack-loader')
|
||||||
|
.get('options')
|
||||||
|
).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
"webpack-virtual-modules": "^0.4.0"
|
"webpack-virtual-modules": "^0.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular-devkit/build-angular": "^14.2.4",
|
"@angular-devkit/build-angular": "^15.0.1",
|
||||||
"@types/css": "0.0.33",
|
"@types/css": "0.0.33",
|
||||||
"@types/jest": "29.1.1",
|
"@types/jest": "29.1.1",
|
||||||
"@types/loader-utils": "2.0.3",
|
"@types/loader-utils": "2.0.3",
|
||||||
|
@ -181,15 +181,19 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
.loader('angular-hot-loader');
|
.loader('angular-hot-loader');
|
||||||
});
|
});
|
||||||
|
|
||||||
const buildAngularPath = getDependencyPath('@angular-devkit/build-angular');
|
const buildAngularMajorVersion = getBuildAngularMajorVersion();
|
||||||
if (buildAngularPath) {
|
if (buildAngularMajorVersion) {
|
||||||
const tsConfig = readTsConfig(tsConfigPath);
|
|
||||||
const { ScriptTarget } = getTypescript();
|
|
||||||
const scriptTarget = tsConfig.options.target ?? ScriptTarget.ESNext;
|
|
||||||
const buildAngularOptions: any = {
|
const buildAngularOptions: any = {
|
||||||
scriptTarget,
|
|
||||||
aot: !disableAOT,
|
aot: !disableAOT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (buildAngularMajorVersion < 15) {
|
||||||
|
const tsConfig = readTsConfig(tsConfigPath);
|
||||||
|
const { ScriptTarget } = getTypescript();
|
||||||
|
buildAngularOptions.scriptTarget =
|
||||||
|
tsConfig.options.target ?? ScriptTarget.ESNext;
|
||||||
|
}
|
||||||
|
|
||||||
if (disableAOT) {
|
if (disableAOT) {
|
||||||
buildAngularOptions.optimize = false;
|
buildAngularOptions.optimize = false;
|
||||||
}
|
}
|
||||||
@ -291,3 +295,24 @@ function getAngularWebpackPlugin(): any {
|
|||||||
const { AngularWebpackPlugin } = require('@ngtools/webpack');
|
const { AngularWebpackPlugin } = require('@ngtools/webpack');
|
||||||
return AngularWebpackPlugin;
|
return AngularWebpackPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MAJOR_VER_RE = /^(\d+)\./;
|
||||||
|
function getBuildAngularMajorVersion() {
|
||||||
|
const buildAngularPath = getDependencyPath('@angular-devkit/build-angular');
|
||||||
|
if (!buildAngularPath) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const buildAngularVersion =
|
||||||
|
require(`${buildAngularPath}/package.json`).version;
|
||||||
|
|
||||||
|
const [_, majorStr] = buildAngularVersion.match(MAJOR_VER_RE);
|
||||||
|
|
||||||
|
return Number(majorStr);
|
||||||
|
} catch (err) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user