-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathwebpack.config.js
108 lines (105 loc) · 2.96 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const HtmlWebpackPlugin = require('html-webpack-plugin');
const DashboardPlugin = require('@module-federation/dashboard-plugin');
const { ModuleFederationPlugin } = require('webpack').container;
const path = require('path');
const { readFileSync } = require('fs');
const env = readFileSync(__dirname + '/../.env')
.toString('utf-8')
.split('\n')
.map(v => v.trim().split('='));
process.env.DASHBOARD_WRITE_TOKEN = env.find(([k]) => k === 'DASHBOARD_WRITE_TOKEN')[1];
process.env.DASHBOARD_BASE_URL = env.find(([k]) => k === 'DASHBOARD_BASE_URL')[1];
module.exports = {
entry: './src/index',
mode: 'development',
devServer: {
static: {
directory: path.join(__dirname, 'dist'),
},
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
},
port: 3002,
},
output: {
filename: '[name].[contenthash].js',
chunkFilename: '[name].[contenthash].js',
publicPath: `auto`,
},
cache: false,
module: {
rules: [
{
test: /\.m?js$/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.less$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
modules: true,
},
},
{
loader: 'less-loader',
options: {
lessOptions: {
javascriptEnabled: true,
math: 'always',
},
},
},
],
},
{
test: /\.jsx?$/,
loader: require.resolve('esbuild-loader'),
exclude: /node_modules/,
options: {
loader: 'jsx',
target: 'es2015',
},
},
],
},
plugins: [
new ModuleFederationPlugin({
name: 'dsl__REMOTE_VERSION__',
library: { type: 'var', name: 'dsl__REMOTE_VERSION__' },
filename: 'remoteEntry.js',
remotes: {},
exposes: {
'./Button': './src/Button',
'./Carousel': './src/Carousel',
'./TextField': './src/TextField',
},
// sharing code based on the installed version, to allow for multiple vendors with different versions
shared: require('./package.json').dependencies,
}),
new HtmlWebpackPlugin({
template: './public/index.html',
}),
new DashboardPlugin({
versionStrategy: `${Date.now()}`,
filename: 'dashboard.json',
environment: 'development',
dashboardURL: `${process.env.DASHBOARD_BASE_URL}/update?token=${process.env.DASHBOARD_WRITE_TOKEN}`,
metadata: {
baseUrl: 'http://localhost:3002',
source: {
url: 'https://github.com/module-federation/federation-dashboard/tree/master/dashboard-example/dsl',
},
remote: 'http://localhost:3002/remoteEntry.js',
},
}),
],
};