Skip to content

Commit

Permalink
angular: add experimental support to esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Nov 27, 2024
1 parent c0469a3 commit fbdef6e
Show file tree
Hide file tree
Showing 22 changed files with 577 additions and 30 deletions.
125 changes: 125 additions & 0 deletions generators/angular/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,23 @@ exports[`generator - angular gateway-jwt-skipUserManagement(true)-withAdminUi(fa
"source": "TaskParameter[source]",
},
],
"mergeClientPackageJson": [
{
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"webpack-bundle-analyzer": null,
"webpack-merge": null,
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
],
}
`;

Expand Down Expand Up @@ -1620,6 +1637,25 @@ exports[`generator - angular gateway-oauth2-withAdminUi(true)-skipJhipsterDepend
"source": "TaskParameter[source]",
},
],
"mergeClientPackageJson": [
{
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"folder-hash": null,
"merge-jsons-webpack-plugin": null,
"webpack-bundle-analyzer": null,
"webpack-merge": null,
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
],
}
`;

Expand Down Expand Up @@ -2304,6 +2340,23 @@ exports[`generator - angular microservice-jwt-skipUserManagement(false)-withAdmi
"config": "targetOptions.target === 'serve' ? {} : require('./webpack.microfrontend')(config, options, targetOptions)",
},
],
"mergeClientPackageJson": [
{
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"webpack-bundle-analyzer": null,
"webpack-merge": null,
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
],
}
`;

Expand Down Expand Up @@ -2994,6 +3047,25 @@ exports[`generator - angular microservice-oauth2-withAdminUi(true)-skipJhipsterD
"config": "targetOptions.target === 'serve' ? {} : require('./webpack.microfrontend')(config, options, targetOptions)",
},
],
"mergeClientPackageJson": [
{
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"folder-hash": null,
"merge-jsons-webpack-plugin": null,
"webpack-bundle-analyzer": null,
"webpack-merge": null,
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
],
}
`;

Expand Down Expand Up @@ -4085,6 +4157,25 @@ exports[`generator - angular monolith-jwt-skipUserManagement(false)-withAdminUi(
"source": "TaskParameter[source]",
},
],
"mergeClientPackageJson": [
{
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"folder-hash": null,
"merge-jsons-webpack-plugin": null,
"webpack-bundle-analyzer": null,
"webpack-merge": null,
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
],
}
`;

Expand Down Expand Up @@ -4755,6 +4846,23 @@ exports[`generator - angular monolith-oauth2-withAdminUi(false)-skipJhipsterDepe
"source": "TaskParameter[source]",
},
],
"mergeClientPackageJson": [
{
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"webpack-bundle-analyzer": null,
"webpack-merge": null,
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
],
}
`;

Expand Down Expand Up @@ -5434,6 +5542,23 @@ exports[`generator - angular monolith-session-skipUserManagement(true)-withAdmin
"source": "TaskParameter[source]",
},
],
"mergeClientPackageJson": [
{
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"webpack-bundle-analyzer": null,
"webpack-merge": null,
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
],
}
`;

Expand Down
31 changes: 29 additions & 2 deletions generators/angular/files-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,48 @@ export const files = {
common: [
clientRootTemplatesBlock({
templates: [
'angular.json',
{ sourceFile: 'eslint.config.js.jhi.angular', destinationFile: ctx => `${ctx.eslintConfigFile}.jhi.angular` },
'ngsw-config.json',
'package.json',
'tsconfig.json',
'tsconfig.app.json',
'tsconfig.spec.json',
'jest.conf.js',
],
}),
],
webpack: [
clientRootTemplatesBlock({
condition: ctx => ctx.clientBundlerWebpack,
templates: [
'angular.json',
'webpack/environment.js',
'webpack/proxy.conf.js',
'webpack/webpack.custom.js',
'webpack/logo-jhipster.png',
],
}),
],
esbuild: [
clientRootTemplatesBlock({
condition: ctx => ctx.clientBundlerExperimentalEsbuild,
templates: [
{ sourceFile: 'angular.json.esbuild', destinationFile: 'angular.json' },
'proxy.conf.json',
'build-plugins/define-esbuild.mjs',
'build-plugins/swagger-esbuild.mjs',
'build-plugins/swagger-middleware.mjs',
],
}),
clientRootTemplatesBlock({
condition: ctx => ctx.clientBundlerExperimentalEsbuild && ctx.enableTranslation,
templates: ['build-plugins/i18n-esbuild.mjs'],
}),
clientSrcTemplatesBlock({
condition: ctx => ctx.clientBundlerExperimentalEsbuild && ctx.enableTranslation,
templates: ['i18n/index.ts'],
}),
],
sass: [
{
...clientSrcTemplatesBlock(),
Expand All @@ -67,7 +94,7 @@ export const files = {
],
microfrontend: [
clientRootTemplatesBlock({
condition: generator => generator.microfrontend,
condition: generator => generator.clientBundlerWebpack && generator.microfrontend,
templates: ['webpack/webpack.microfrontend.js'],
}),
{
Expand Down
53 changes: 53 additions & 0 deletions generators/angular/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ export default class AngularGenerator extends BaseApplicationGenerator {
}
};

source.addLanguagesInFrontend = ({ languagesDefinition }) => {
if (application.clientBundlerExperimentalEsbuild) {
this.editFile(
`${application.clientSrcDir}i18n/index.ts`,
createNeedleCallback({
needle: 'i18n-language-loader',
contentToAdd: languagesDefinition.map(
lang => `'${lang.languageTag}': async (): Promise<any> => import('i18n/${lang.languageTag}.json'),`,
),
}),
createNeedleCallback({
needle: 'i18n-language-angular-loader',
contentToAdd: languagesDefinition.map(
lang => `'${lang.languageTag}': async (): Promise<void> => import('@angular/common/locales/${lang.languageTag}'),`,
),
}),
);
}
};

source.addIconImport = args => {
const iconsPath = `${application.srcMainWebapp}app/config/font-awesome-icons.ts`;
const ignoreNonExisting = this.sharedData.getControl().ignoreNeedlesError && 'Icon imports not updated with icon';
Expand Down Expand Up @@ -266,6 +286,39 @@ export default class AngularGenerator extends BaseApplicationGenerator {

get postWriting() {
return this.asPostWritingTaskGroup({
clientBundler({ application, source }) {
const { clientBundlerExperimentalEsbuild, enableTranslation, nodeDependencies } = application;
if (clientBundlerExperimentalEsbuild) {
source.mergeClientPackageJson!({
devDependencies: {
'@angular-builders/custom-esbuild': null,
...(enableTranslation ? { 'folder-hash': null, deepmerge: null } : {}),
},
});
} else {
source.mergeClientPackageJson!({
dependencies: enableTranslation
? {
'@ngx-translate/http-loader': null,
}
: {},
devDependencies: {
'@angular-builders/custom-webpack': null,
'browser-sync-webpack-plugin': null,
'copy-webpack-plugin': null,
'eslint-webpack-plugin': null,
'webpack-bundle-analyzer': null,
'webpack-merge': null,
'webpack-notifier': null,
...(enableTranslation ? { 'folder-hash': null, 'merge-jsons-webpack-plugin': null } : {}),
},
overrides: {
'browser-sync': nodeDependencies['browser-sync'],
webpack: nodeDependencies.webpack,
},
});
}
},
addWebsocketDependencies({ application, source }) {
const { authenticationTypeSession, communicationSpringWebsocket, nodeDependencies } = application;
const dependencies = {};
Expand Down
2 changes: 2 additions & 0 deletions generators/angular/resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"devDependencies": {
"@angular-architects/module-federation": "18.0.6",
"@angular-architects/module-federation-runtime": "18.0.6",
"@angular-builders/custom-esbuild": "18.0.0",
"@angular-builders/custom-webpack": "18.0.0",
"@angular-builders/jest": "18.0.0",
"@angular/cli": "18.2.12",
Expand All @@ -33,6 +34,7 @@
"browser-sync-webpack-plugin": "2.3.0",
"buffer": "6.0.3",
"copy-webpack-plugin": "12.0.2",
"deepmerge": "4.3.1",
"eslint": "9.15.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.2.1",
Expand Down
4 changes: 3 additions & 1 deletion generators/angular/support/update-languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ function updateLanguagesInWebpackTask(this: BaseGenerator, { application, contro
export default function updateLanguagesTask(this: BaseGenerator, param: UpdateClientLanguagesTaskParam) {
updateLanguagesInPipeTask.call(this, param);
updateLanguagesInConstantsTask.call(this, param);
updateLanguagesInWebpackTask.call(this, param);
if (param.application.clientBundlerWebpack) {
updateLanguagesInWebpackTask.call(this, param);
}
updateLanguagesInDayjsConfigurationTask.call(this, param, { configurationFile: `${param.application.clientSrcDir}app/config/dayjs.ts` });
}
Loading

0 comments on commit fbdef6e

Please sign in to comment.