Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
122 lines (120 loc) · 3.49 KB
/
Copy pathwebpack.config.js
File metadata and controls
122 lines (120 loc) · 3.49 KB
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
120
121
122
const CopyWebpackPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");
const { mergeWithRules } = require("webpack-merge");
const singleSpaDefaults = require("webpack-config-single-spa-react-ts");
const path = require("path");
module.exports = (webpackConfigEnv, argv) => {
const defaultConfig = singleSpaDefaults({
orgName: "madie",
projectName: "madie-layout",
webpackConfigEnv,
orgPackagesAsExternal: false,
disableHtmlGeneration: true, // false causes multiple assets served as index.html
outputSystemJS: true,
argv,
});
// const mergeConfig
// We need to override the css loading rule from the parent configuration
// so that we can add postcss-loader to the chain
const externalsConfig = {
externals: [
"@madie/madie-auth",
"@madie/madie-cql-library",
"@madie/madie-measure",
"@madie/madie-admin",
"@madie/madie-util",
// Shared singleton libraries — loaded once via import map
"@emotion/react",
"@emotion/styled",
"styled-components",
],
};
const newCssRule = {
module: {
rules: [
{
test: /\.css$/i,
include: [/node_modules/, /src/],
use: [
"style-loader",
"css-loader", // uses modules: true, which I think we want. Parent does not
"postcss-loader",
],
},
{
test: /\.scss$/,
resolve: {
extensions: [".scss", ".sass"],
},
use: [
{
loader: "style-loader",
},
{
loader: "css-loader",
options: { sourceMap: true, importLoaders: 2 },
},
{
loader: "postcss-loader",
options: {
sourceMap: true,
},
},
{
loader: "sass-loader",
},
],
exclude: /node_modules/,
},
// teach webpack how to read the binaries. file-loader doesn't work in webpack 5
{
test: /\.(woff2?|ttf|otf|eot)$/,
type: "asset/resource",
},
],
},
plugins: [
// react-draggable (used by the design system's MadieDialog) contains
// `if (process.env.DRAGGABLE_DEBUG) ...` which runs on every mousedown
// inside a dialog. Webpack 5 does not shim the Node `process` global in
// browser bundles and only replaces `process.env.NODE_ENV`, Defining
// the flag makes webpack substitute `false` at build time, so `process`
// is never evaluated in the browser (and the dead branch is stripped in
// production builds).
new webpack.DefinePlugin({
"process.env.DRAGGABLE_DEBUG": JSON.stringify(false),
}),
],
};
// we need to pull out the styles and images, import them with scss.
const copyConfig = {
resolve: {
fallback: {
fs: false,
},
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: "node_modules/@madie/madie-design-system/fonts/",
to: path.resolve("public/fonts"),
},
{
from: "node_modules/@madie/madie-design-system/images/",
to: path.resolve("public/images"),
},
],
}),
],
};
return mergeWithRules({
module: {
rules: {
test: "match",
use: "replace",
},
},
plugins: "append",
})(externalsConfig, defaultConfig, newCssRule, copyConfig);
};