forked from kaoto-archive/kaoto-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
119 lines (116 loc) · 3.47 KB
/
webpack.common.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
109
110
111
112
113
114
115
116
117
118
119
/* eslint-disable */
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const { dependencies, federatedModuleName } = require('./package.json');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
// const CopyPlugin = require('copy-webpack-plugin');
// const FederatedTypesPlugin = require('@module-federation/typescript');
const isPatternflyStyles = (stylesheet) =>
stylesheet.includes('@patternfly/react-core/') ||
stylesheet.includes('@patternfly/react-code-editor') ||
stylesheet.includes('monaco-editor-webpack-plugin');
const deps = require('./package.json').dependencies;
module.exports = () => {
return {
entry: path.resolve(__dirname, 'src', 'index.tsx'),
module: {
rules: [
{
test: /\.(tsx|ts|jsx)?$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
},
],
},
{
test: /\.css|s[ac]ss$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
include: (stylesheet) => !isPatternflyStyles(stylesheet),
sideEffects: true,
},
{
test: /\.css$/,
include: isPatternflyStyles,
use: ['null-loader'],
sideEffects: true,
},
{
test: /\.(ttf|eot|woff|woff2)$/,
type: 'asset/resource',
},
{
test: /\.(svg|jpg|jpeg|png|gif)$/i,
type: 'asset/inline',
},
],
},
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: 'auto',
},
optimization: {
splitChunks: false,
},
plugins: [
new HtmlWebpackPlugin({
favicon: path.resolve(__dirname, 'src/assets/images', 'favicon.svg'),
template: path.resolve(__dirname, 'public', 'index.html'),
}),
new Dotenv({
systemvars: true,
silent: true,
}),
new MonacoWebpackPlugin({
languages: ['yaml'],
globalAPI: true,
}),
new MiniCssExtractPlugin({
insert: (linkTag) => {
const preloadLinkTag = document.createElement('link');
preloadLinkTag.rel = 'preload';
preloadLinkTag.as = 'style';
preloadLinkTag.href = linkTag.href;
document.head.appendChild(preloadLinkTag);
document.head.appendChild(linkTag);
},
}),
// new CopyPlugin({
// patterns: [
// {
// from: path.resolve(__dirname, 'src', '@kaoto'),
// to: path.resolve(__dirname, 'dist', '@kaoto'),
// },
// ],
// }),
new webpack.container.ModuleFederationPlugin({
name: federatedModuleName,
filename: 'remoteEntry.js',
library: { type: 'var', name: federatedModuleName },
// exposes: ['./src/@kaoto/index.ts'],
shared: {
...deps,
},
}),
// new FederatedTypesPlugin(),
],
resolve: {
extensions: ['.js', '.ts', '.tsx', '.jsx'],
plugins: [
new TsconfigPathsPlugin({
configFile: path.resolve(__dirname, './tsconfig.json'),
}),
],
symlinks: false,
cacheWithContext: false,
},
};
};