-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwebpack.config.js
More file actions
151 lines (149 loc) · 4.2 KB
/
Copy pathwebpack.config.js
File metadata and controls
151 lines (149 loc) · 4.2 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const HtmlWebpackPlugin = require("html-webpack-plugin");
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
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-root",
"@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",
},
],
},
devServer: {
static: [
{
directory: path.join(__dirname, "local-dev-env"),
publicPath: "/importmap",
},
{
directory: path.join(
__dirname,
"node_modules/@madie/madie-root/dist/"
),
publicPath: "/",
},
{
directory: path.join(
__dirname,
"node_modules/@madie/madie-auth/dist/"
),
publicPath: "/madie-auth",
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(
__dirname,
"node_modules/@madie/madie-root/dist/index.html"
),
}),
// 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);
};