mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 02:54:11 +08:00
feat(webpack): disable aot flag, optional angular dep and tsconfig utils (#9711)
Co-authored-by: Igor Randjelovic <rigor789@gmail.com>
This commit is contained in:
@ -400,7 +400,8 @@ exports[`angular configuration for android 1`] = `
|
|||||||
new AngularWebpackPlugin(
|
new AngularWebpackPlugin(
|
||||||
{
|
{
|
||||||
tsconfig: '__jest__/tsconfig.json',
|
tsconfig: '__jest__/tsconfig.json',
|
||||||
directTemplateLoading: false
|
directTemplateLoading: false,
|
||||||
|
jitMode: false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@ -816,7 +817,8 @@ exports[`angular configuration for ios 1`] = `
|
|||||||
new AngularWebpackPlugin(
|
new AngularWebpackPlugin(
|
||||||
{
|
{
|
||||||
tsconfig: '__jest__/tsconfig.json',
|
tsconfig: '__jest__/tsconfig.json',
|
||||||
directTemplateLoading: false
|
directTemplateLoading: false,
|
||||||
|
jitMode: false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
@ -54,6 +54,7 @@
|
|||||||
"webpack-virtual-modules": "^0.4.0"
|
"webpack-virtual-modules": "^0.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@angular-devkit/build-angular": "^13.1.2",
|
||||||
"@types/css": "0.0.33",
|
"@types/css": "0.0.33",
|
||||||
"@types/jest": "27.0.1",
|
"@types/jest": "27.0.1",
|
||||||
"@types/loader-utils": "2.0.3",
|
"@types/loader-utils": "2.0.3",
|
||||||
|
@ -3,8 +3,11 @@ import { extname, resolve } from 'path';
|
|||||||
import Config from 'webpack-chain';
|
import Config from 'webpack-chain';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
|
|
||||||
|
import { getDependencyPath } from '../helpers/dependencies';
|
||||||
import { getProjectFilePath } from '../helpers/project';
|
import { getProjectFilePath } from '../helpers/project';
|
||||||
import { env as _env, IWebpackEnv } from '../index';
|
import { env as _env, IWebpackEnv } from '../index';
|
||||||
|
import { readTsConfig } from '../helpers/tsconfig';
|
||||||
|
import { warnOnce } from '../helpers/log';
|
||||||
import {
|
import {
|
||||||
getEntryDirPath,
|
getEntryDirPath,
|
||||||
getEntryPath,
|
getEntryPath,
|
||||||
@ -22,6 +25,8 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
getProjectFilePath('tsconfig.json'),
|
getProjectFilePath('tsconfig.json'),
|
||||||
].find((path) => existsSync(path));
|
].find((path) => existsSync(path));
|
||||||
|
|
||||||
|
const disableAOT = !!env.disableAOT;
|
||||||
|
|
||||||
// remove default ts rule
|
// remove default ts rule
|
||||||
config.module.rules.delete('ts');
|
config.module.rules.delete('ts');
|
||||||
|
|
||||||
@ -158,6 +163,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
{
|
{
|
||||||
tsconfig: tsConfigPath,
|
tsconfig: tsConfigPath,
|
||||||
directTemplateLoading: false,
|
directTemplateLoading: false,
|
||||||
|
jitMode: disableAOT,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -169,6 +175,18 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
.use('angular-hot-loader')
|
.use('angular-hot-loader')
|
||||||
.loader('angular-hot-loader');
|
.loader('angular-hot-loader');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const buildAngularPath = getDependencyPath('@angular-devkit/build-angular');
|
||||||
|
if (buildAngularPath) {
|
||||||
|
const tsConfig = readTsConfig(tsConfigPath);
|
||||||
|
const scriptTarget = tsConfig.options.target ?? ScriptTarget.ESNext;
|
||||||
|
const buildAngularOptions: any = {
|
||||||
|
scriptTarget,
|
||||||
|
aot: !disableAOT,
|
||||||
|
};
|
||||||
|
if (disableAOT) {
|
||||||
|
buildAngularOptions.optimize = false;
|
||||||
|
}
|
||||||
// zone + async/await
|
// zone + async/await
|
||||||
config.module
|
config.module
|
||||||
.rule('angular-webpack-loader')
|
.rule('angular-webpack-loader')
|
||||||
@ -182,10 +200,15 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
.before('angular')
|
.before('angular')
|
||||||
.use('webpack-loader')
|
.use('webpack-loader')
|
||||||
.loader('@angular-devkit/build-angular/src/babel/webpack-loader')
|
.loader('@angular-devkit/build-angular/src/babel/webpack-loader')
|
||||||
.options({
|
.options(buildAngularOptions);
|
||||||
scriptTarget: ScriptTarget.ESNext,
|
} else {
|
||||||
aot: true,
|
warnOnce(
|
||||||
});
|
'build-angular-missing',
|
||||||
|
`
|
||||||
|
@angular-devkit/build-angular is missing! Some features may not work as expected. Please install it manually to get rid of this warning.
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// look for platform specific polyfills first
|
// look for platform specific polyfills first
|
||||||
|
@ -26,6 +26,7 @@ import {
|
|||||||
getPlatform,
|
getPlatform,
|
||||||
getPlatformName,
|
getPlatformName,
|
||||||
} from './platform';
|
} from './platform';
|
||||||
|
import { readTsConfig } from './tsconfig';
|
||||||
|
|
||||||
// intentionally populated manually
|
// intentionally populated manually
|
||||||
// as this generates nicer typings
|
// as this generates nicer typings
|
||||||
@ -75,4 +76,7 @@ export default {
|
|||||||
addVirtualEntry,
|
addVirtualEntry,
|
||||||
addVirtualModule,
|
addVirtualModule,
|
||||||
},
|
},
|
||||||
|
tsconfig: {
|
||||||
|
readTsConfig,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
19
packages/webpack5/src/helpers/tsconfig.ts
Normal file
19
packages/webpack5/src/helpers/tsconfig.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { readConfigFile, parseJsonConfigFileContent, sys } from 'typescript';
|
||||||
|
import { dirname } from 'path';
|
||||||
|
|
||||||
|
export function readTsConfig(path: string) {
|
||||||
|
const f = readConfigFile(path, sys.readFile);
|
||||||
|
|
||||||
|
const parsed = parseJsonConfigFileContent(
|
||||||
|
f.config,
|
||||||
|
{
|
||||||
|
fileExists: sys.fileExists,
|
||||||
|
readFile: sys.readFile,
|
||||||
|
readDirectory: sys.readDirectory,
|
||||||
|
useCaseSensitiveFileNames: true,
|
||||||
|
},
|
||||||
|
dirname(path)
|
||||||
|
);
|
||||||
|
|
||||||
|
return parsed;
|
||||||
|
}
|
Reference in New Issue
Block a user