|
| 1 | +import { appTools, defineConfig } from '@modern-js/app-tools'; |
| 2 | +import { serverPlugin } from '@modern-js/plugin-server'; |
| 3 | +import { |
| 4 | + // DependencyReferencExportPlugin, |
| 5 | + IndependentSharePlugin, |
| 6 | + ModuleFederationPlugin, |
| 7 | +} from '@module-federation/enhanced'; |
| 8 | +import mfConfig from './module-federation.config'; |
| 9 | +import path from 'path'; |
| 10 | + |
| 11 | +const isReShake = process.env.RE_SHAKE; |
| 12 | +if (isReShake) { |
| 13 | + process.env.MF_CUSTOM_REFERENCED_EXPORTS = JSON.stringify({ |
| 14 | + antd: ['Divider', 'Space', 'Switch', 'Button', 'Badge'], |
| 15 | + }); |
| 16 | +} |
| 17 | + |
| 18 | +const webpackConfig = { |
| 19 | + cache: false, |
| 20 | +}; |
| 21 | + |
| 22 | +if (isReShake) { |
| 23 | + // @ts-ignore |
| 24 | + webpackConfig.entry = { |
| 25 | + main: 'data:application/node;base64,', |
| 26 | + }; |
| 27 | + // @ts-ignore |
| 28 | + webpackConfig.output = { |
| 29 | + path: path.resolve(__dirname, 'dist-test'), |
| 30 | + }; |
| 31 | +} |
| 32 | + |
| 33 | +const publicPath = 'http://localhost:3001/'; |
| 34 | + |
| 35 | +// https://modernjs.dev/en/configure/app/usage |
| 36 | +export default defineConfig({ |
| 37 | + runtime: { |
| 38 | + router: true, |
| 39 | + }, |
| 40 | + dev: { |
| 41 | + assetPrefix: publicPath, |
| 42 | + }, |
| 43 | + output: { |
| 44 | + assetPrefix: publicPath, |
| 45 | + polyfill: 'off', |
| 46 | + disableTsChecker: true, |
| 47 | + }, |
| 48 | + server: { |
| 49 | + port: 3001, |
| 50 | + }, |
| 51 | + plugins: [ |
| 52 | + appTools({ |
| 53 | + bundler: 'webpack', // Set to 'webpack' to enable webpack |
| 54 | + }), |
| 55 | + serverPlugin(), |
| 56 | + ], |
| 57 | + performance: { |
| 58 | + chunkSplit: { |
| 59 | + strategy: 'split-by-module', |
| 60 | + }, |
| 61 | + }, |
| 62 | + source: { |
| 63 | + enableAsyncEntry: true, |
| 64 | + transformImport: false, |
| 65 | + }, |
| 66 | + tools: { |
| 67 | + webpack: webpackConfig, |
| 68 | + bundlerChain(chain) { |
| 69 | + chain.optimization.moduleIds('named'); |
| 70 | + chain.optimization.chunkIds('named'); |
| 71 | + chain.optimization.mangleExports(false); |
| 72 | + // enable in dev |
| 73 | + chain.optimization.usedExports(true); |
| 74 | + // chain.optimization.minimize(false) |
| 75 | + chain.optimization.runtimeChunk(false); |
| 76 | + if (isReShake) { |
| 77 | + chain.plugin('IndependentSharePlugin').use(IndependentSharePlugin, [ |
| 78 | + { |
| 79 | + // @ts-ignore |
| 80 | + mfConfig, |
| 81 | + outputDir: 'independent-packages', |
| 82 | + treeshake: true, |
| 83 | + }, |
| 84 | + ]); |
| 85 | + } else { |
| 86 | + chain.plugin('MF').use(ModuleFederationPlugin, [mfConfig]); |
| 87 | + } |
| 88 | + }, |
| 89 | + }, |
| 90 | +}); |
0 commit comments