vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

在项目中该如何配置,使得vite的模块联邦打包出来的js转为es5?

Open zjjaxx opened this issue 2 years ago • 1 comments

Versions

  • originjs:
  • node:

Reproduction

import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import Components from 'unplugin-vue-components/vite'; import { VantResolver } from 'unplugin-vue-components/resolvers'; import federation from "@originjs/vite-plugin-federation"; import path from "path"; import legacy from "@vitejs/plugin-legacy"; import { serverUrlMap, burialUrlMap,channelIdMap } from "./src/utils/config"; import { viteVConsole } from "vite-plugin-vconsole";

// https://vitejs.dev/config/ export default defineConfig({ plugins: [ legacy({}), vue(), Components({ resolvers: [VantResolver()], }), federation({ name: "router-remote", filename: "remoteEntry.js", exposes: { "./ElementPlus": "./src/views/oss.vue" }, shared: ["vue", "vue-router", "vuex", "vant"] }) ], build:{ target:"esnext", rollupOptions:{ // https://rollupjs.org/guide/en/#big-list-of-options output:{ manualChunks(id) { if (id.includes('node_modules')) { return 'vendor'; } } } }, }, });

Steps to reproduce

What is Expected?

打包出来的js格式是es5

What is actually happening?

打包报错 No corresponding legacy polyfill chunk found

zjjaxx avatar Jul 01 '22 01:07 zjjaxx

I'm afraid that it's not supported yet. If we use the ESM format by default, it will depend to the top-level await feature, so we have to set the target:'esnext'.

export default defineConfig({
  build: {
	target: 'esnext',
  }
})

But you can also try the system format, which I have not tried.

ygj6 avatar Jul 02 '22 08:07 ygj6