Skip to content

Commit

Permalink
vue: migrate microfrontend to rsbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Oct 7, 2024
1 parent c3ef1d2 commit 0aa42f7
Show file tree
Hide file tree
Showing 18 changed files with 461 additions and 39 deletions.
3 changes: 3 additions & 0 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"cjsExtension": ".cjs",
"clientBundler": "webpack",
"clientBundlerAny": true,
"clientBundlerRsbuild": false,
"clientBundlerVite": false,
"clientBundlerWebpack": true,
"clientDistDir": "target/classes/static/",
Expand Down Expand Up @@ -900,6 +901,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"cjsExtension": ".cjs",
"clientBundler": "webpack",
"clientBundlerAny": true,
"clientBundlerRsbuild": false,
"clientBundlerVite": false,
"clientBundlerWebpack": true,
"clientDistDir": "target/classes/static/",
Expand Down Expand Up @@ -1539,6 +1541,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"cjsExtension": ".cjs",
"clientBundler": undefined,
"clientBundlerAny": true,
"clientBundlerRsbuild": false,
"clientBundlerVite": false,
"clientBundlerWebpack": false,
"clientDistDir": "target/classes/static/",
Expand Down
2 changes: 1 addition & 1 deletion generators/client/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const command = {
type: String,
hide: true,
},
choices: ['webpack', 'vite'],
choices: ['webpack', 'vite', 'rsbuild'],
scope: 'storage',
},
microfrontend: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ task webapp_test(type: NpmTask) {
.withPropertyName("postcssrc")
.withPathSensitivity(PathSensitivity.RELATIVE)
<%_ } _%>
<%_ if (clientBundlerRsbuild && clientFrameworkBuiltIn) { _%>
inputs.files('rsbuild.config.ts')
.withPropertyName("rsbuild")
.withPathSensitivity(PathSensitivity.RELATIVE)
<%_ } _%>
<%_ if (clientBundlerVite && clientFrameworkBuiltIn) { _%>
inputs.files("vite.config.mts")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generator - javascript:rsbuild with defaults options should call source snapshot 1`] = `{}`;

exports[`generator - javascript:rsbuild with defaults options should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
},
"package.json": {
"stateCleared": "modified",
},
"rsbuild.config.ts.jhi": {
"stateCleared": "modified",
},
}
`;
26 changes: 26 additions & 0 deletions generators/javascript/generators/rsbuild/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright 2013-2024 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { JHipsterCommandDefinition } from '../../../../lib/command/types.js';

const command = {
configs: {},
import: [],
} as const satisfies JHipsterCommandDefinition;

export default command;
53 changes: 53 additions & 0 deletions generators/javascript/generators/rsbuild/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright 2013-2024 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { basename, dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { before, describe, expect, it } from 'esmocha';

import { shouldSupportFeatures, testBlueprintSupport } from '../../../../test/support/tests.js';
import { defaultHelpers as helpers, result } from '../../../../lib/testing/index.js';
import Generator from './index.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const generator = `${basename(resolve(__dirname, '../../'))}:${basename(__dirname)}`;

describe(`generator - ${generator}`, () => {
shouldSupportFeatures(Generator);
describe('blueprint support', () => testBlueprintSupport(generator));

describe('with defaults options', () => {
before(async () => {
await helpers.runJHipster(generator).withMockedJHipsterGenerators().withMockedSource().withSharedApplication({}).withJHipsterConfig();
});

it('should match files snapshot', () => {
expect(result.getStateSnapshot()).toMatchSnapshot();
});

it('should call source snapshot', () => {
expect(result.sourceCallsArg).toMatchSnapshot();
});

it('should compose with generators', () => {
expect(result.composedMockedGenerators).toMatchInlineSnapshot(`[]`);
});
});
});
131 changes: 131 additions & 0 deletions generators/javascript/generators/rsbuild/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* Copyright 2013-2024 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import BaseGenerator from '../../../../generators/base-application/index.js';

export default class RspackGenerator extends BaseGenerator {
constructor(args, options, features) {
super(args, options, { queueCommandTasks: true, ...features });
}

async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints();
}

if (!this.delegateToBlueprint) {
await this.dependsOnBootstrapApplication();
}
}

get preparing() {
return this.asPreparingTaskGroup({});
}

get [BaseGenerator.PREPARING]() {
return this.delegateTasksToBlueprint(() => this.preparing);
}

get postPreparing() {
return this.asPostPreparingTaskGroup({});
}

get [BaseGenerator.POST_PREPARING]() {
return this.delegateTasksToBlueprint(() => this.postPreparing);
}

get preparingEachEntity() {
return this.asPreparingEachEntityTaskGroup({});
}

get [BaseGenerator.PREPARING_EACH_ENTITY]() {
return this.delegateTasksToBlueprint(() => this.preparingEachEntity);
}

get preparingEachEntityField() {
return this.asPreparingEachEntityFieldTaskGroup({});
}

get [BaseGenerator.PREPARING_EACH_ENTITY_FIELD]() {
return this.delegateTasksToBlueprint(() => this.preparingEachEntityField);
}

get preparingEachEntityRelationship() {
return this.asPreparingEachEntityRelationshipTaskGroup({});
}

get [BaseGenerator.PREPARING_EACH_ENTITY_RELATIONSHIP]() {
return this.delegateTasksToBlueprint(() => this.preparingEachEntityRelationship);
}

get postPreparingEachEntity() {
return this.asPostPreparingEachEntityTaskGroup({});
}

get [BaseGenerator.POST_PREPARING_EACH_ENTITY]() {
return this.delegateTasksToBlueprint(() => this.postPreparingEachEntity);
}

get default() {
return this.asDefaultTaskGroup({});
}

get [BaseGenerator.DEFAULT]() {
return this.delegateTasksToBlueprint(() => this.default);
}

get writing() {
return this.asWritingTaskGroup({
async writeFiles({ application }) {
await this.writeFiles({
blocks: [{ templates: ['rsbuild.config.ts.jhi'] }],
context: application,
});
},
});
}

get [BaseGenerator.WRITING]() {
return this.delegateTasksToBlueprint(() => this.writing);
}

get postWriting() {
return this.asPostWritingTaskGroup({
addScripts({ application }) {
const { clientPackageManager } = application;
this.packageJson.merge({
devDependencies: {
'@rsbuild/core': 'latest',
},
scripts: {
start: 'rsbuild dev',
build: 'rsbuild build',
'webapp:build:dev': `${clientPackageManager} run build -- --mode=development`,
'webapp:build:prod': `${clientPackageManager} run build -- --mode=production`,
'webapp:dev': `${clientPackageManager} run start`,
'webapp:serve': `${clientPackageManager} start`,
},
});
},
});
}

get [BaseGenerator.POST_WRITING]() {
return this.delegateTasksToBlueprint(() => this.postWriting);
}
}
20 changes: 20 additions & 0 deletions generators/javascript/generators/rsbuild/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright 2013-2024 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { default } from './generator.js';
export { default as command } from './command.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<%#
Copyright 2013-2024 the original author or authors from the JHipster project.
This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-%>
<&_
// Register sections and max allowed fragments, 0 for unlimited.
fragments.registerSections({
importsSection: 0,
pluginsSection: 0,
configSection: 0,
});
_&>
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from '@rsbuild/core';
<&- fragments.importsSection() -&>

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export default defineConfig({
root: path.join(__dirname, '<%- this.relativeDir(clientRootDir, clientSrcDir) %>'),
output: {
cleanDistPath: true,
distPath: {
root: path.join(__dirname, './<%= this.relativeDir(clientRootDir, clientDistDir) %>'),
},
},
html: {
template: './index.html',
scriptLoading: 'defer',
tags: [
{
tag: 'base',
attrs: { href: '/' },
},
],
},
plugins: [
<&- fragments.pluginsSection() -&>
],
<&- fragments.configSection() -&>
});
3 changes: 3 additions & 0 deletions generators/maven/generators/frontend-plugin/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class FrontendPluginGenerator extends BaseApplicationGenerator {
clientFrameworkBuiltIn,
clientBundlerVite,
clientBundlerWebpack,
clientBundlerRsbuild,
microfrontend,
srcMainWebapp,
} = application;
Expand All @@ -69,6 +70,8 @@ export default class FrontendPluginGenerator extends BaseApplicationGenerator {
checksumIncludedFiles.push('webpack/*.*');
} else if (clientBundlerVite) {
checksumIncludedFiles.push('vite.config.mts');
} else if (clientBundlerRsbuild) {
checksumIncludedFiles.push('rsbuild.config.ts');
}
}
source.addMavenDefinition!({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ public class SecurityConfiguration {
.requestMatchers(mvc.pattern("/*.ico"), mvc.pattern("/*.png"), mvc.pattern("/*.svg"), mvc.pattern("/*.webapp")).permitAll()
<%_ if (clientBundlerVite) { _%>
.requestMatchers(mvc.pattern("/assets/**")).permitAll()
<%_ } else if (clientBundlerRsbuild) { _%>
.requestMatchers(mvc.pattern("/static/**")).permitAll()
<%_ } else { _%>
.requestMatchers(mvc.pattern("/app/**")).permitAll()
.requestMatchers(mvc.pattern("/i18n/**")).permitAll()
Expand Down Expand Up @@ -225,6 +227,8 @@ public class SecurityConfiguration {
// microfrontend resources are loaded by webpack without authentication, they need to be public
<%_ if (clientBundlerVite) { _%>
.requestMatchers(mvc.pattern("/services/*/assets/**")).permitAll()
<%_ } else if (clientBundlerRsbuild) { _%>
.requestMatchers(mvc.pattern("/services/*/static/**")).permitAll()
<%_ } _%>
.requestMatchers(mvc.pattern("/services/*/*.js")).permitAll()
.requestMatchers(mvc.pattern("/services/*/*.txt")).permitAll()
Expand Down
Loading

0 comments on commit 0aa42f7

Please sign in to comment.