Skip to content

Commit b6132db

Browse files
committed
vue: migrate microfrontend to rsbuild
1 parent 8ddf7a1 commit b6132db

File tree

18 files changed

+453
-38
lines changed

18 files changed

+453
-38
lines changed

generators/app/__snapshots__/generator.spec.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
256256
"cjsExtension": ".cjs",
257257
"clientBundler": "webpack",
258258
"clientBundlerAny": true,
259+
"clientBundlerRsbuild": false,
259260
"clientBundlerVite": false,
260261
"clientBundlerWebpack": true,
261262
"clientDistDir": "target/classes/static/",
@@ -900,6 +901,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
900901
"cjsExtension": ".cjs",
901902
"clientBundler": "webpack",
902903
"clientBundlerAny": true,
904+
"clientBundlerRsbuild": false,
903905
"clientBundlerVite": false,
904906
"clientBundlerWebpack": true,
905907
"clientDistDir": "target/classes/static/",
@@ -1539,6 +1541,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
15391541
"cjsExtension": ".cjs",
15401542
"clientBundler": undefined,
15411543
"clientBundlerAny": true,
1544+
"clientBundlerRsbuild": false,
15421545
"clientBundlerVite": false,
15431546
"clientBundlerWebpack": false,
15441547
"clientDistDir": "target/classes/static/",

generators/client/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const command = {
8282
type: String,
8383
hide: true,
8484
},
85-
choices: ['webpack', 'vite'],
85+
choices: ['webpack', 'vite', 'rsbuild'],
8686
scope: 'storage',
8787
},
8888
microfrontend: {

generators/gradle/generators/node-gradle/templates/buildSrc/src/main/groovy/jhipster.node-gradle-conventions.gradle.ejs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ task webapp_test(type: NpmTask) {
7171
.withPropertyName("postcssrc")
7272
.withPathSensitivity(PathSensitivity.RELATIVE)
7373
<%_ } _%>
74+
<%_ if (clientBundlerRsbuild && clientFrameworkBuiltIn) { _%>
75+
76+
inputs.files('rsbuild.config.ts')
77+
.withPropertyName("rsbuild")
78+
.withPathSensitivity(PathSensitivity.RELATIVE)
79+
<%_ } _%>
7480
<%_ if (clientBundlerVite && clientFrameworkBuiltIn) { _%>
7581
7682
inputs.files("vite.config.mts")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`generator - javascript:rsbuild with defaults options should call source snapshot 1`] = `{}`;
4+
5+
exports[`generator - javascript:rsbuild with defaults options should match files snapshot 1`] = `
6+
{
7+
".yo-rc.json": {
8+
"stateCleared": "modified",
9+
},
10+
"package.json": {
11+
"stateCleared": "modified",
12+
},
13+
"rsbuild.config.ts.jhi": {
14+
"stateCleared": "modified",
15+
},
16+
}
17+
`;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright 2013-2024 the original author or authors from the JHipster project.
3+
*
4+
* This file is part of the JHipster project, see https://www.jhipster.tech/
5+
* for more information.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* https://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
import type { JHipsterCommandDefinition } from '../../../../lib/command/types.js';
20+
21+
const command = {
22+
configs: {},
23+
import: [],
24+
} as const satisfies JHipsterCommandDefinition;
25+
26+
export default command;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright 2013-2024 the original author or authors from the JHipster project.
3+
*
4+
* This file is part of the JHipster project, see https://www.jhipster.tech/
5+
* for more information.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* https://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
import { basename, dirname, resolve } from 'node:path';
20+
import { fileURLToPath } from 'node:url';
21+
import { before, describe, expect, it } from 'esmocha';
22+
23+
import { shouldSupportFeatures, testBlueprintSupport } from '../../../../test/support/tests.js';
24+
import { defaultHelpers as helpers, result } from '../../../../lib/testing/index.js';
25+
import Generator from './index.js';
26+
27+
const __filename = fileURLToPath(import.meta.url);
28+
const __dirname = dirname(__filename);
29+
30+
const generator = `${basename(resolve(__dirname, '../../'))}:${basename(__dirname)}`;
31+
32+
describe(`generator - ${generator}`, () => {
33+
shouldSupportFeatures(Generator);
34+
describe('blueprint support', () => testBlueprintSupport(generator));
35+
36+
describe('with defaults options', () => {
37+
before(async () => {
38+
await helpers.runJHipster(generator).withMockedJHipsterGenerators().withMockedSource().withSharedApplication({}).withJHipsterConfig();
39+
});
40+
41+
it('should match files snapshot', () => {
42+
expect(result.getStateSnapshot()).toMatchSnapshot();
43+
});
44+
45+
it('should call source snapshot', () => {
46+
expect(result.sourceCallsArg).toMatchSnapshot();
47+
});
48+
49+
it('should compose with generators', () => {
50+
expect(result.composedMockedGenerators).toMatchInlineSnapshot(`[]`);
51+
});
52+
});
53+
});
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/**
2+
* Copyright 2013-2024 the original author or authors from the JHipster project.
3+
*
4+
* This file is part of the JHipster project, see https://www.jhipster.tech/
5+
* for more information.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* https://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
import BaseGenerator from '../../../../generators/base-application/index.js';
20+
21+
export default class RspackGenerator extends BaseGenerator {
22+
constructor(args, options, features) {
23+
super(args, options, { queueCommandTasks: true, ...features });
24+
}
25+
26+
async beforeQueue() {
27+
if (!this.fromBlueprint) {
28+
await this.composeWithBlueprints();
29+
}
30+
31+
if (!this.delegateToBlueprint) {
32+
await this.dependsOnBootstrapApplication();
33+
}
34+
}
35+
36+
get preparing() {
37+
return this.asPreparingTaskGroup({});
38+
}
39+
40+
get [BaseGenerator.PREPARING]() {
41+
return this.delegateTasksToBlueprint(() => this.preparing);
42+
}
43+
44+
get postPreparing() {
45+
return this.asPostPreparingTaskGroup({});
46+
}
47+
48+
get [BaseGenerator.POST_PREPARING]() {
49+
return this.delegateTasksToBlueprint(() => this.postPreparing);
50+
}
51+
52+
get preparingEachEntity() {
53+
return this.asPreparingEachEntityTaskGroup({});
54+
}
55+
56+
get [BaseGenerator.PREPARING_EACH_ENTITY]() {
57+
return this.delegateTasksToBlueprint(() => this.preparingEachEntity);
58+
}
59+
60+
get preparingEachEntityField() {
61+
return this.asPreparingEachEntityFieldTaskGroup({});
62+
}
63+
64+
get [BaseGenerator.PREPARING_EACH_ENTITY_FIELD]() {
65+
return this.delegateTasksToBlueprint(() => this.preparingEachEntityField);
66+
}
67+
68+
get preparingEachEntityRelationship() {
69+
return this.asPreparingEachEntityRelationshipTaskGroup({});
70+
}
71+
72+
get [BaseGenerator.PREPARING_EACH_ENTITY_RELATIONSHIP]() {
73+
return this.delegateTasksToBlueprint(() => this.preparingEachEntityRelationship);
74+
}
75+
76+
get postPreparingEachEntity() {
77+
return this.asPostPreparingEachEntityTaskGroup({});
78+
}
79+
80+
get [BaseGenerator.POST_PREPARING_EACH_ENTITY]() {
81+
return this.delegateTasksToBlueprint(() => this.postPreparingEachEntity);
82+
}
83+
84+
get default() {
85+
return this.asDefaultTaskGroup({});
86+
}
87+
88+
get [BaseGenerator.DEFAULT]() {
89+
return this.delegateTasksToBlueprint(() => this.default);
90+
}
91+
92+
get writing() {
93+
return this.asWritingTaskGroup({
94+
async writeFiles({ application }) {
95+
await this.writeFiles({
96+
blocks: [{ templates: ['rsbuild.config.ts.jhi'] }],
97+
context: application,
98+
});
99+
},
100+
});
101+
}
102+
103+
get [BaseGenerator.WRITING]() {
104+
return this.delegateTasksToBlueprint(() => this.writing);
105+
}
106+
107+
get postWriting() {
108+
return this.asPostWritingTaskGroup({
109+
addScripts({ application }) {
110+
const { clientPackageManager } = application;
111+
this.packageJson.merge({
112+
devDependencies: {
113+
'@rsbuild/core': 'latest',
114+
},
115+
scripts: {
116+
start: 'rsbuild dev',
117+
build: 'rsbuild build',
118+
'webapp:build:dev': `${clientPackageManager} run build -- --mode=development`,
119+
'webapp:build:prod': `${clientPackageManager} run build -- --mode=production`,
120+
'webapp:dev': `${clientPackageManager} run start`,
121+
'webapp:serve': `${clientPackageManager} start`,
122+
},
123+
});
124+
},
125+
});
126+
}
127+
128+
get [BaseGenerator.POST_WRITING]() {
129+
return this.delegateTasksToBlueprint(() => this.postWriting);
130+
}
131+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright 2013-2024 the original author or authors from the JHipster project.
3+
*
4+
* This file is part of the JHipster project, see https://www.jhipster.tech/
5+
* for more information.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* https://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
export { default } from './generator.js';
20+
export { default as command } from './command.js';
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<%#
2+
Copyright 2013-2024 the original author or authors from the JHipster project.
3+
4+
This file is part of the JHipster project, see https://www.jhipster.tech/
5+
for more information.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
https://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
-%>
19+
<&_
20+
// Register sections and max allowed fragments, 0 for unlimited.
21+
fragments.registerSections({
22+
importsSection: 0,
23+
pluginsSection: 0,
24+
configSection: 0,
25+
});
26+
_&>
27+
import path from 'node:path';
28+
import { fileURLToPath } from 'node:url';
29+
import { defineConfig } from '@rsbuild/core';
30+
<&- fragments.importsSection() -&>
31+
32+
const __filename = fileURLToPath(import.meta.url);
33+
const __dirname = path.dirname(__filename);
34+
35+
export default defineConfig({
36+
root: path.join(__dirname, '<%- this.relativeDir(clientRootDir, clientSrcDir) %>'),
37+
output: {
38+
cleanDistPath: true,
39+
distPath: {
40+
root: path.join(__dirname, './<%= this.relativeDir(clientRootDir, clientDistDir) %>'),
41+
},
42+
},
43+
html: {
44+
template: './index.html',
45+
scriptLoading: 'defer',
46+
tags: [
47+
{
48+
tag: 'base',
49+
attrs: { href: '/' },
50+
},
51+
],
52+
},
53+
plugins: [
54+
<&- fragments.pluginsSection() -&>
55+
],
56+
<&- fragments.configSection() -&>
57+
});

generators/maven/generators/frontend-plugin/generator.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default class FrontendPluginGenerator extends BaseApplicationGenerator {
4343
clientFrameworkBuiltIn,
4444
clientBundlerVite,
4545
clientBundlerWebpack,
46+
clientBundlerRsbuild,
4647
microfrontend,
4748
srcMainWebapp,
4849
} = application;
@@ -69,6 +70,8 @@ export default class FrontendPluginGenerator extends BaseApplicationGenerator {
6970
checksumIncludedFiles.push('webpack/*.*');
7071
} else if (clientBundlerVite) {
7172
checksumIncludedFiles.push('vite.config.mts');
73+
} else if (clientBundlerRsbuild) {
74+
checksumIncludedFiles.push('rsbuild.config.ts');
7275
}
7376
}
7477
source.addMavenDefinition!({

generators/spring-boot/templates/src/main/java/_package_/config/SecurityConfiguration_imperative.java.ejs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ public class SecurityConfiguration {
196196
.requestMatchers(mvc.pattern("/*.ico"), mvc.pattern("/*.png"), mvc.pattern("/*.svg"), mvc.pattern("/*.webapp")).permitAll()
197197
<%_ if (clientBundlerVite) { _%>
198198
.requestMatchers(mvc.pattern("/assets/**")).permitAll()
199+
<%_ } else if (clientBundlerRsbuild) { _%>
200+
.requestMatchers(mvc.pattern("/static/**")).permitAll()
199201
<%_ } else { _%>
200202
.requestMatchers(mvc.pattern("/app/**")).permitAll()
201203
.requestMatchers(mvc.pattern("/i18n/**")).permitAll()
@@ -225,6 +227,8 @@ public class SecurityConfiguration {
225227
// microfrontend resources are loaded by webpack without authentication, they need to be public
226228
<%_ if (clientBundlerVite) { _%>
227229
.requestMatchers(mvc.pattern("/services/*/assets/**")).permitAll()
230+
<%_ } else if (clientBundlerRsbuild) { _%>
231+
.requestMatchers(mvc.pattern("/services/*/static/**")).permitAll()
228232
<%_ } _%>
229233
.requestMatchers(mvc.pattern("/services/*/*.js")).permitAll()
230234
.requestMatchers(mvc.pattern("/services/*/*.txt")).permitAll()

0 commit comments

Comments
 (0)