|
| 1 | +import path from 'path' |
| 2 | +import url from 'url' |
| 3 | +import webpack from 'webpack' |
| 4 | +import packageJson from '../package.json' assert { type: 'json' } |
| 5 | + |
| 6 | +const { ModuleFederationPlugin } = webpack.container |
| 7 | + |
| 8 | +// Extract some properties from the package.json file to avoid duplication |
| 9 | +const deps = packageJson.peerDependencies |
| 10 | + |
| 11 | +const __filename = url.fileURLToPath(import.meta.url) |
| 12 | +const __dirname = path.dirname(__filename) |
| 13 | + |
| 14 | +const DEV_SERVER_PORT = 4001 |
| 15 | + |
| 16 | +export default { |
| 17 | + mode: 'development', |
| 18 | + devtool: false, |
| 19 | + target: 'web', |
| 20 | + optimization: { |
| 21 | + minimize: false, |
| 22 | + runtimeChunk: false, |
| 23 | + splitChunks: { |
| 24 | + chunks: 'async', |
| 25 | + name: false, |
| 26 | + }, |
| 27 | + }, |
| 28 | + entry: './src/index.ts', |
| 29 | + output: { |
| 30 | + clean: true, |
| 31 | + path: path.resolve(__dirname, 'dist'), |
| 32 | + publicPath: 'auto', |
| 33 | + }, |
| 34 | + resolve: { |
| 35 | + extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'], |
| 36 | + }, |
| 37 | + plugins: [ |
| 38 | + new ModuleFederationPlugin({ |
| 39 | + name: 'createNetwork', |
| 40 | + filename: 'remoteEntry.js', |
| 41 | + remotes: { |
| 42 | + // Import some data providers from the host application |
| 43 | + cyweb: 'cyweb@http://localhost:5500/remoteEntry.js', |
| 44 | + }, |
| 45 | + exposes: { |
| 46 | + './CreateNetworkApp': './src/CreateNetworkApp', |
| 47 | + './CreateNetworkPanel': './src/components/CreateNetworkPanel.tsx', |
| 48 | + }, |
| 49 | + shared: { |
| 50 | + react: { singleton: true, requiredVersion: deps.react }, |
| 51 | + 'react-dom': { singleton: true, requiredVersion: deps['react-dom'] }, |
| 52 | + }, |
| 53 | + }), |
| 54 | + ], |
| 55 | + module: { |
| 56 | + rules: [ |
| 57 | + { |
| 58 | + test: /\.tsx?$/, |
| 59 | + use: 'ts-loader', |
| 60 | + exclude: /node_modules/, |
| 61 | + }, |
| 62 | + ], |
| 63 | + }, |
| 64 | + devServer: { |
| 65 | + hot: true, |
| 66 | + port: DEV_SERVER_PORT, |
| 67 | + headers: { |
| 68 | + 'Access-Control-Allow-Origin': '*', // allow access from any origin |
| 69 | + }, |
| 70 | + }, |
| 71 | +} |
0 commit comments