Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate vue microfrontends to rsbuild #27344

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', 'experimentalEsbuild'],
choices: ['webpack', 'vite', 'experimentalEsbuild', 'rsbuild'],
scope: 'storage',
},
devServerPort: {
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,86 @@
<%#
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,
configsSection: 0,
});
_&>
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { mergeRsbuildConfig } from '@rsbuild/core';
import { getAbsoluteFSPath } from 'swagger-ui-dist';
<&- fragments.importsSection() -&>

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

export default mergeRsbuildConfig({
root: path.join(__dirname, '<%- this.relativeDir(clientRootDir, clientSrcDir) %>'),
output: {
<%_ if (microfrontend) { _%>
assetPrefix: 'auto',
<%_ } _%>
cleanDistPath: true,
distPath: {
root: path.join(__dirname, './<%= this.relativeDir(clientRootDir, clientDistDir) %>'),
},
},
copy: [
{
// https://github.com/swagger-api/swagger-ui/blob/v4.6.1/swagger-ui-dist-package/README.md
context: getAbsoluteFSPath(),
from: '*.{js,css,html,png}',
to: 'swagger-ui/',
globOptions: { ignore: ['**/index.html'] },
},
{
from: path.join(path.dirname(require.resolve('axios/package.json')), 'dist/axios.min.js'),
to: 'swagger-ui/',
},
{ from: './<%= this.relativeDir(clientRootDir, clientSrcDir) %>swagger-ui/', to: 'swagger-ui/' },
{ from: './<%= this.relativeDir(clientRootDir, clientSrcDir) %>content/', to: 'content/' },
{ from: './<%= this.relativeDir(clientRootDir, clientSrcDir) %>favicon.ico', to: 'favicon.ico' },
{
from: './<%= this.relativeDir(clientRootDir, clientSrcDir) %>manifest.webapp',
to: 'manifest.webapp',
},
// jhipster-needle-add-assets-to-webpack - JHipster will add/remove third-party resources in this array
{ from: './<%= this.relativeDir(clientRootDir, clientSrcDir) %>robots.txt', to: 'robots.txt' },
],
html: {
template: './index.html',
scriptLoading: 'defer',
tags: [
{
tag: 'base',
attrs: { href: '/' },
},
],
},
plugins: [
<&- fragments.pluginsSection() -&>
],
<&- fragments.configSection() -&>
},
<&- fragments.configsSection() -&>
);
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ public class SecurityConfiguration {
<%_ } else if (clientBundlerExperimentalEsbuild) { _%>
.requestMatchers(mvc.pattern("/content/**")).permitAll()
.requestMatchers(mvc.pattern("/resources/**")).permitAll()
<%_ } else if (clientBundlerRsbuild) { _%>
.requestMatchers(mvc.pattern("/static/**")).permitAll()
<%_ } else { _%>
.requestMatchers(mvc.pattern("/app/**")).permitAll()
.requestMatchers(mvc.pattern("/i18n/**")).permitAll()
Expand Down Expand Up @@ -220,6 +222,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
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ public class SecurityConfiguration {
<%_ } else if (clientBundlerExperimentalEsbuild) { _%>
"/content/**",
"/resources/**",
<%_ } else if (clientBundlerRsbuild) { _%>
"/static/**",
<%_ } else { _%>
"/app/**",
"/i18n/**",
Expand Down Expand Up @@ -289,6 +291,9 @@ public class SecurityConfiguration {
<%_ if (clientBundlerVite) { _%>
.pathMatchers("/services/*/assets/**").permitAll()
.pathMatchers("/services/*/*.js").permitAll()
<%_ } else if (clientBundlerRsbuild) { _%>
.pathMatchers("/services/*/static/**").permitAll()
.pathMatchers("/services/*/*.js").permitAll()
<%_ } else { _%>
.pathMatchers("/services/*/*.js").permitAll()
.pathMatchers("/services/*/*.txt").permitAll()
Expand Down
Loading
Loading