-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.ts
101 lines (97 loc) · 2.65 KB
/
webpack.config.ts
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
import { join, resolve } from "path";
import { Configuration, ProvidePlugin } from "webpack";
const ReactDocgenTypescriptPlugin =
require("react-docgen-typescript-plugin").default;
process.env.NODE_ENV = "development";
process.env.DEBUG = "docgen*";
process.env.FAST_REFRESH = "false";
const configFactory =
require("@muritavo/webpack-microfrontend-scripts/bin/react/scripts/_webpackConfiguration").createBaseConfiguration;
const baseConfig: Configuration = configFactory(
__dirname,
process.env.NODE_ENV
);
baseConfig.output!.libraryTarget = "umd";
baseConfig.plugins = baseConfig.plugins!.filter(
(a) =>
![
"ReactRefreshPlugin",
"ModuleFederationPlugin",
"SourceMapDevToolPlugin",
].includes(a.constructor.name)
);
const plugins = (baseConfig as any).module.rules[0].use.options
.plugins as string[];
plugins.shift();
delete baseConfig.entry;
baseConfig.module!.rules![0] = {
test: /\.m?[j|t]sx?$/,
exclude: /node_modules/,
use: {
loader: "esbuild-loader",
options: {
target: "es2015",
},
},
};
// console.log()
// process.exit(0)
baseConfig.module!.rules!.push(
{
test: /\.m?js$/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.svg$/i,
use: [
{
loader: "babel-loader",
options: {
// Allow customization from babelrc from the application folder
babelrcRoots: ["./"],
presets: [
["@babel/preset-env", { targets: "defaults" }],
[
"@babel/preset-react",
{
runtime: "automatic",
},
],
["@babel/preset-typescript"],
],
sourceType: "unambiguous",
},
},
require.resolve(
"@muritavo/webpack-microfrontend-scripts/bin/shared/loaders/ImageResolutionOptimizer/namedSVG"
),
{
loader: require.resolve("@svgr/webpack"),
options: {
exportType: "named",
babel: false,
},
},
require.resolve(
"@muritavo/webpack-microfrontend-scripts/bin/shared/loaders/ImageResolutionOptimizer/extractImages"
),
],
issuer: {
and: [/\.(scss)$/],
},
}
);
baseConfig.plugins.push(
new ReactDocgenTypescriptPlugin({
shouldExtractLiteralValuesFromEnum: true,
shouldRemoveUndefinedFromOptional: true,
propFilter: function (prop) {
return prop.parent ? !/node_modules/.test(prop.parent.fileName) : true;
},
// NOTE: this default cannot be changed
savePropValueAsString: true,
})
);
export default baseConfig;