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

Vite mf #27493

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Vite mf #27493

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
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
node_modules
package-lock.json
.git
<%_ if (clientFrameworkVue && microfrontend) { _%>
'.__mf__temp',
<%_ } _%>

<&- fragments.render({ join: '\n\n' }) &>
22 changes: 16 additions & 6 deletions generators/vue/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,27 @@ export default class VueGenerator extends BaseApplicationGenerator {
}
},
addMicrofrontendDependencies({ application }) {
if (!application.microfrontend) return;
if (application.clientBundlerVite) {
const { applicationTypeGateway, clientBundlerVite, clientBundlerWebpack, enableTranslation, microfrontend } = application;
if (!microfrontend) return;
if (clientBundlerVite) {
this.packageJson.merge({
dependencies: applicationTypeGateway ? {
'@module-federation/runtime': null,
} : {},
devDependencies: {
'@originjs/vite-plugin-federation': '1.3.6',
'@module-federation/vite': null,
},
});
} else if (application.clientBundlerWebpack) {
} else if (clientBundlerWebpack) {
if (applicationTypeGateway) {
this.packageJson.merge({
devDependencies: {
'@module-federation/utilities': null,
},
});
}
this.packageJson.merge({
devDependencies: {
'@module-federation/utilities': null,
'browser-sync-webpack-plugin': null,
'copy-webpack-plugin': null,
'css-loader': null,
Expand All @@ -234,7 +244,7 @@ export default class VueGenerator extends BaseApplicationGenerator {
'webpack-dev-server': null,
'webpack-merge': null,
'workbox-webpack-plugin': null,
...(application.enableTranslation
...(enableTranslation
? {
'folder-hash': null,
'merge-jsons-webpack-plugin': null,
Expand Down
2 changes: 2 additions & 0 deletions generators/vue/resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"@fortawesome/fontawesome-svg-core": "6.6.0",
"@fortawesome/free-solid-svg-icons": "6.6.0",
"@fortawesome/vue-fontawesome": "3.0.8",
"@module-federation/runtime": "0.6.9",
"@stomp/rx-stomp": "2.0.0",
"@vuelidate/core": "2.0.3",
"@vuelidate/validators": "2.0.4",
Expand All @@ -23,6 +24,7 @@
"devDependencies": {
"@eslint/js": "9.12.0",
"@module-federation/utilities": "3.1.15",
"@module-federation/vite": "1.1.1",
"@pinia/testing": "0.1.6",
"@tsconfig/node18": "18.2.4",
"@types/node": "20.11.25",
Expand Down
8 changes: 7 additions & 1 deletion generators/vue/templates/eslint.config.js.jhi.vue.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ import vue from 'eslint-plugin-vue';

<&_ } -&>
<&_ if (fragment.configSection) { -&>
{ ignores: ['<%- this.relativeDir(clientRootDir, clientDistDir) %>', '<%- temporaryDir %>'] },
{ ignores: [
<%_ if (microfrontend) { _%>
'.__mf__temp',
<%_ } _%>
'<%- this.relativeDir(clientRootDir, clientDistDir) %>',
'<%- temporaryDir %>',
] },
js.configs.recommended,
...tseslint.configs.recommended.map(config =>
config.name === 'typescript-eslint/base' ? config : { ...config, files: [ '**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts' ] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import EntitiesMenu from '@/entities/entities-menu.vue';
import { useStore } from '@/store';
import { useRouter } from 'vue-router';
<%_ if (applicationTypeGateway && microfrontend) { _%>
<%_ if (clientBundlerVite) { _%>
import { loadRemote } from '@module-federation/runtime';
<%_ } else { _%>
import { importRemote } from '@module-federation/utilities';
<%_ } _%>
<%_ } _%>

export default defineComponent({
Expand All @@ -23,11 +27,16 @@ export default defineComponent({
<%_ if (applicationTypeGateway && microfrontend) { _%>
<%_ for (const remote of microfrontends) { _%>
'<%= remote.lowercaseBaseName %>-menu': defineAsyncComponent(() => {
<%_ if (clientBundlerVite) { _%>
return loadRemote<any>(`<%= remote.lowercaseBaseName %>/entities-menu`)
.catch(() => import('@/core/error/error-loading.vue'));
<%_ } else { _%>
return importRemote<any>({
url: `./<%= remote.endpointPrefix %>`,
scope: '<%= remote.lowercaseBaseName %>',
module: './entities-menu',
}).catch(() => import('@/core/error/error-loading.vue'));
<%_ } _%>
}),
<%_ } _%>
<%_ } _%>
Expand Down
20 changes: 20 additions & 0 deletions generators/vue/templates/src/main/webapp/app/router/index.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { createRouter as createVueRouter, createWebHistory<% if (applicationTypeGateway && microfrontend) { %>, type RouteRecordRaw<% } %> } from 'vue-router';
<%_ if (applicationTypeGateway && microfrontend) { _%>
<%_ if (clientBundlerVite) { _%>
import { loadRemote, registerRemotes } from '@module-federation/runtime';
<%_ } else { _%>
import { importRemote } from '@module-federation/utilities';
<%_ } _%>
<%_ } _%>

const Home = () => import('@/core/home/home.vue');
Expand Down Expand Up @@ -44,13 +48,29 @@ export const createRouter = () => createVueRouter({
const router = createRouter();

<%_ if (applicationTypeGateway && microfrontend) { _%>
<%_ if (clientBundlerVite) { _%>
registerRemotes([
<%_ for (const remote of microfrontends) { _%>
{
name: '<%= remote.lowercaseBaseName %>',
entry: './<%= remote.endpointPrefix %>/remoteEntry.js',
type: 'module',
},
<%_ } _%>
]);
<%_ } _%>

export const lazyRoutes = Promise.all([
<%_ for (const remote of microfrontends) { _%>
<%_ if (clientBundlerVite) { _%>
loadRemote<any>(`<%= remote.lowercaseBaseName %>/entities-router`)
<%_ } else { _%>
importRemote<any>({
url: `./<%= remote.endpointPrefix %>`,
scope: '<%= remote.lowercaseBaseName %>',
module: './entities-router',
})
<%_ } _%>
.then(<%= remote.lowercaseBaseName %>Router => {
router.addRoute(<%= remote.lowercaseBaseName %>Router.default as RouteRecordRaw);
return <%= remote.lowercaseBaseName %>Router.default;
Expand Down
79 changes: 11 additions & 68 deletions generators/vue/templates/vite.config.mts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@
import { fileURLToPath, URL } from 'node:url';
import { normalizePath } from 'vite'

import {
<%_ if (microfrontend && clientBundlerVite) { _%>
mergeConfig,
<%_ } _%>
defineConfig,
} from 'vite';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { viteStaticCopy } from 'vite-plugin-static-copy';
<%_ if (microfrontend && clientBundlerVite) { _%>
import federation from "@originjs/vite-plugin-federation";

<%_ if (applicationTypeGateway) { _%>
const sharedAppVersion = '0.0.0';
<%_ } _%>
import { federation } from '@module-federation/vite';
import federationConfig from './module-federation.config.cjs';
<%_ } _%>

const { getAbsoluteFSPath } = await import('swagger-ui-dist');
Expand All @@ -55,13 +47,21 @@ let config = defineConfig({
},
],
}),
<%_ if (microfrontend && clientBundlerVite) { _%>
federation(federationConfig),
<%_ } _%>
],
root: fileURLToPath(new URL('./<%- this.relativeDir(clientRootDir, clientSrcDir) %>', import.meta.url)),
publicDir: fileURLToPath(new URL('./<%- this.relativeDir(clientRootDir, clientDistDir) %>public', import.meta.url)),
cacheDir: fileURLToPath(new URL('./<%- this.relativeDir(clientRootDir, temporaryDir) %>.vite-cache', import.meta.url)),
build: {
emptyOutDir: true,
outDir: fileURLToPath(new URL('./<%- this.relativeDir(clientRootDir, clientDistDir) %>', import.meta.url)),
<%_ if (microfrontend && clientBundlerVite) { _%>
modulePreload: false,
// Allow topLevelAwait by default, Use 'vite-plugin-top-level-await' plugin for lower target
target: ['chrome89', 'edge89', 'firefox89', 'safari15'],
<%_ } _%>
rollupOptions: {
input: {
app: fileURLToPath(new URL('./<%- this.relativeDir(clientRootDir, clientSrcDir) %>index.html', import.meta.url)),
Expand Down Expand Up @@ -116,63 +116,6 @@ let config = defineConfig({
},
});

<%_ if (microfrontend && clientBundlerVite) { _%>
config = mergeConfig(config, {
build: {
modulePreload: false,
minify: false,
target: ['chrome89', 'edge89', 'firefox89', 'safari15'],
},
plugins: [
federation({
name: '<%= lowercaseBaseName %>',
<%_ if (applicationTypeGateway) { _%>
remotes: {
<%_ for (const remote of microfrontends) { _%>
'@<%= remote.lowercaseBaseName %>': `/<%= remote.endpointPrefix %>/assets/remoteEntry.js`,
<%_ } _%>
},
<%_ } _%>
<%_ if (applicationTypeMicroservice) { _%>
exposes: {
'./entities-router': './<%= this.relativeDir(clientRootDir, clientSrcDir) %>app/router/entities',
'./entities-menu': './<%= this.relativeDir(clientRootDir, clientSrcDir) %>app/entities/entities-menu.vue',
},
<%_ } _%>
shared: {
'@vuelidate/core': {},
'@vuelidate/validators': {},
axios: {},
// 'bootstrap-vue': {},
vue: {
packagePath: '@vue/compat/dist/vue.esm-bundler.js',
},
'vue-i18n': {},
'vue-router': {},
pinia: {},
'@/shared/security/authority': {
packagePath: './<%= this.relativeDir(clientRootDir, clientSrcDir) %>app/shared/security/authority',
<%_ if (applicationTypeGateway) { _%>
version: sharedAppVersion,
<%_ } _%>
},
'@/shared/alert/alert.service': {
packagePath: './<%= this.relativeDir(clientRootDir, clientSrcDir) %>app/shared/alert/alert.service',
<%_ if (applicationTypeGateway) { _%>
version: sharedAppVersion,
<%_ } _%>
},
'@/locale/translation.service': {
packagePath: './<%= this.relativeDir(clientRootDir, clientSrcDir) %>app/locale/translation.service',
<%_ if (applicationTypeGateway) { _%>
version: sharedAppVersion,
<%_ } _%>
},
},
}),
],
});
<%_ } _%>
// jhipster-needle-add-vite-config - JHipster will add custom config

export default config;
2 changes: 1 addition & 1 deletion lib/jhipster/default-application-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function getConfigForClientApplication(options: ApplicationDefaults = {})
options[CLIENT_THEME_VARIANT] = 'primary';
}
if (clientFramework === 'vue') {
options.clientBundler = options.microfrontend || options.applicationType === 'microservice' ? 'webpack' : 'vite';
options.clientBundler = 'vite';
} else if (clientFramework === 'react') {
options.clientBundler = 'webpack';
} else if (clientFramework === 'angular') {
Expand Down
Loading