-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrspack.config.js
81 lines (80 loc) · 2.24 KB
/
rspack.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
const { HtmlRspackPlugin, container: {ModuleFederationPlugin} } = require('@rspack/core');
const path = require('path');
const package = require('./package.json');
const isDevelopment = process.env.NODE_ENV === "development";
const name = `${isDevelopment? "local_" : ""}${package.name.replaceAll("-","_")}`;
const port = 3003;
module.exports = {
entry: './src/index',
mode: 'development',
target: 'web',
devServer: {
static: {
directory: path.join(__dirname, 'dist'),
},
port,
setupMiddlewares: (middlewares, devServer) => {
console.log(`\x1b[32m[webdeck-plugin] Plugin url:\x1b[0m \x1b[36mhttp://localhost:${port}/remoteEntry.js?name=${name}\x1b[0m \n`)
return middlewares;
},
},
output: {
publicPath: 'auto',
},
optimization:{
minimize:false
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
include: path.resolve(__dirname, 'src'),
use: {
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'ecmascript',
jsx: true,
},
transform: {
react: {
runtime: 'automatic',
},
},
},
},
},
},
],
},
plugins: [
new ModuleFederationPlugin({
name: name,
library: {
type: 'global',
name: name.replaceAll("-", "_")
},
filename: 'remoteEntry.js',
exposes: {
'./Plugin': './src/App',
},
shared: {
react: {
requiredVersion: package.dependencies.react,
import: 'react', // the "react" package will be used a provided and fallback module
shareKey: 'react', // under this name the shared module will be placed in the share scope
shareScope: 'default', // share scope with this name will be used
singleton: true, // only a single version of the shared module is allowed
},
'react-dom': {
requiredVersion: package.dependencies['react-dom'],
singleton: true, // only a single version of the shared module is allowed
},
},
}),
new HtmlRspackPlugin({
template: './public/index.html',
}),
],
};