-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
83 lines (77 loc) · 2.16 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import path from 'path'
import url from 'url'
import webpack from 'webpack'
import packageJson from '../package.json' with { type: 'json' }
const { ModuleFederationPlugin } = webpack.container
// Extract some properties from the package.json file to avoid duplication
const deps = packageJson.peerDependencies
const __filename = url.fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const DEV_SERVER_PORT = 3333
export default (env = {}) => {
// Extract the environment variables to modify URLs and other settings
const isProduction = env.production || false
const cywebUrl = isProduction
? 'cyweb@https://web.cytoscape.org/remoteEntry.js'
: 'cyweb@http://localhost:5500/remoteEntry.js'
return {
mode: 'development',
devtool: false,
target: 'web',
optimization: {
minimize: false,
runtimeChunk: false,
splitChunks: {
chunks: 'async',
name: false,
},
},
entry: './src/index.ts',
output: {
clean: true,
path: path.resolve(__dirname, 'dist'),
publicPath: 'auto',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
},
plugins: [
new ModuleFederationPlugin({
name: 'simpleMenu',
filename: 'remoteEntry.js',
remotes: {
// Import some data providers from the host application
cyweb: cywebUrl,
},
exposes: {
'./SimpleMenuApp': './src/SimpleMenuApp',
'./AppMenuItem': './src/components/AppMenuItem',
},
shared: {
react: { singleton: true, requiredVersion: deps.react },
'react-dom': { singleton: true, requiredVersion: deps['react-dom'] },
'@mui/material': {
singleton: true,
requiredVersion: deps['@mui/material'],
},
},
}),
],
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
devServer: {
hot: true,
port: DEV_SERVER_PORT,
headers: {
'Access-Control-Allow-Origin': '*', // allow access from any origin
},
},
}
}