@@ -21,13 +21,13 @@ async function getWebpackEntries() {
21
21
22
22
return {
23
23
id : entryName ,
24
- path : path . relative ( workspaceRoot , path . dirname ( componentPath ) ) ,
24
+ import : `@mui/material/ ${ componentName } ` ,
25
25
} ;
26
26
} ,
27
27
) ;
28
28
29
29
const corePackagePath = path . join ( workspaceRoot , 'packages/mui-base/build' ) ;
30
- const coreComponents = ( await glob ( path . join ( corePackagePath , '([A-Z])*/index.js' ) ) ) . map (
30
+ const baseComponents = ( await glob ( path . join ( corePackagePath , '([A-Z])*/index.js' ) ) ) . map (
31
31
( componentPath ) => {
32
32
const componentName = path . basename ( path . dirname ( componentPath ) ) ;
33
33
let entryName = componentName ;
@@ -38,7 +38,7 @@ async function getWebpackEntries() {
38
38
39
39
return {
40
40
id : entryName ,
41
- path : path . relative ( workspaceRoot , path . dirname ( componentPath ) ) ,
41
+ import : `@mui/base/ ${ componentName } ` ,
42
42
} ;
43
43
} ,
44
44
) ;
@@ -50,7 +50,7 @@ async function getWebpackEntries() {
50
50
51
51
return {
52
52
id : componentName ,
53
- path : path . relative ( workspaceRoot , path . dirname ( componentPath ) ) ,
53
+ import : `@mui/lab/ ${ componentName } ` ,
54
54
} ;
55
55
} ,
56
56
) ;
@@ -62,7 +62,7 @@ async function getWebpackEntries() {
62
62
63
63
return {
64
64
id : `@mui/joy/${ componentName } ` ,
65
- path : path . relative ( workspaceRoot , path . dirname ( componentPath ) ) ,
65
+ import : `@mui/joy/ ${ componentName } ` ,
66
66
} ;
67
67
} ,
68
68
) ;
@@ -72,62 +72,63 @@ async function getWebpackEntries() {
72
72
// WARNING: Changing the name will break tracking of bundle size over time
73
73
// If the name of the package changes, rename its display name in https://github.com/eps1lon/mui-contributor-dashboard/blob/main/src/pages/SizeComparison.tsx
74
74
id : '@material-ui/core' ,
75
- path : path . join ( path . relative ( workspaceRoot , materialPackagePath ) , 'index.js' ) ,
75
+ import : '@mui/material' ,
76
76
} ,
77
77
...materialComponents ,
78
78
{
79
79
id : '@material-ui/lab' ,
80
- path : path . join ( path . relative ( workspaceRoot , labPackagePath ) , 'index.js' ) ,
80
+ import : '@mui/lab' ,
81
81
} ,
82
82
...labComponents ,
83
83
{
84
84
id : '@material-ui/styles' ,
85
- path : 'packages/ mui-styles/build/index.js ' ,
85
+ import : '@ mui/styles ' ,
86
86
} ,
87
87
{
88
88
id : '@material-ui/private-theming' ,
89
- path : 'packages/ mui- private-theming/build/index.js ' ,
89
+ import : '@ mui/ private-theming' ,
90
90
} ,
91
91
{
92
92
id : '@material-ui/system' ,
93
- path : 'packages/ mui-system/build/index.js ' ,
93
+ import : '@ mui/system ' ,
94
94
} ,
95
95
{
96
96
id : 'createBox' ,
97
- path : 'packages/ mui- system/build/ createBox/index.js ' ,
97
+ import : '@ mui/ system/createBox' ,
98
98
} ,
99
99
{
100
100
id : 'createStyled' ,
101
- path : 'packages/ mui- system/build/ createStyled/index.js ' ,
101
+ import : '@ mui/ system/createStyled' ,
102
102
} ,
103
103
{
104
104
id : '@material-ui/core/styles/createTheme' ,
105
- path : 'packages/mui-material/build/styles/createTheme.js' ,
105
+ importName : 'createTheme' ,
106
+ import : '@mui/material/styles' ,
106
107
} ,
107
108
{
108
109
id : 'colorManipulator' ,
109
- path : 'packages/ mui- system/build/ colorManipulator/index.js ' ,
110
+ import : '@ mui/ system/colorManipulator' ,
110
111
} ,
111
112
{
112
113
id : 'useAutocomplete' ,
113
- path : 'packages/ mui- lab/build/ useAutocomplete/index.js ' ,
114
+ import : '@ mui/ lab/useAutocomplete' ,
114
115
} ,
115
116
{
116
117
id : '@material-ui/core/useMediaQuery' ,
117
- path : 'packages/ mui- material/build/ useMediaQuery/index.js ' ,
118
+ import : '@ mui/ material/useMediaQuery' ,
118
119
} ,
119
120
{
120
121
id : '@material-ui/core/useScrollTrigger' ,
121
- path : 'packages/ mui- material/build/ useScrollTrigger/index.js ' ,
122
+ import : '@ mui/ material/useScrollTrigger' ,
122
123
} ,
123
124
{
124
125
id : '@material-ui/unstyled' ,
125
- path : path . join ( path . relative ( workspaceRoot , corePackagePath ) , 'index.js' ) ,
126
+ import : '@mui/base' ,
126
127
} ,
127
- ...coreComponents ,
128
+ ...baseComponents ,
128
129
{
129
130
id : '@material-ui/utils' ,
130
- path : 'packages/ mui-utils/build/esm/index.js ' ,
131
+ import : '@ mui/utils ' ,
131
132
} ,
132
133
// TODO: Requires webpack v5
133
134
// Resolution of webpack/acorn to 7.x is blocked by nextjs (https://github.com/vercel/next.js/issues/11947)
@@ -138,7 +139,7 @@ async function getWebpackEntries() {
138
139
// },
139
140
{
140
141
id : '@mui/joy' ,
141
- path : path . join ( path . relative ( workspaceRoot , joyPackagePath ) , 'index.js' ) ,
142
+ import : '@mui/joy' ,
142
143
} ,
143
144
...joyComponents ,
144
145
] ;
@@ -148,6 +149,8 @@ function createWebpackConfig(entry, environment) {
148
149
const analyzerMode = environment . analyze ? 'static' : 'disabled' ;
149
150
const concatenateModules = ! environment . accurateBundles ;
150
151
152
+ const importNames = entry . importName ? `{ ${ entry . importName } as foo }` : '* as foo' ;
153
+
151
154
/**
152
155
* @type {import('webpack').Configuration }
153
156
*/
@@ -160,7 +163,7 @@ function createWebpackConfig(entry, environment) {
160
163
concatenateModules,
161
164
minimizer : [
162
165
new TerserPlugin ( {
163
- test : / \. j s ( \? .* ) ? $ / i,
166
+ test : / \. m ? j s ( \? .* ) ? $ / i,
164
167
} ) ,
165
168
] ,
166
169
} ,
@@ -174,6 +177,11 @@ function createWebpackConfig(entry, environment) {
174
177
} ,
175
178
path : path . join ( __dirname , 'build' ) ,
176
179
} ,
180
+ resolve : {
181
+ alias : {
182
+ '@mui/utils' : '@mui/utils/esm' ,
183
+ } ,
184
+ } ,
177
185
plugins : [
178
186
new CompressionPlugin ( ) ,
179
187
new BundleAnalyzerPlugin ( {
@@ -186,7 +194,14 @@ function createWebpackConfig(entry, environment) {
186
194
reportFilename : `${ entry . id } .html` ,
187
195
} ) ,
188
196
] ,
189
- entry : { [ entry . id ] : path . join ( workspaceRoot , entry . path ) } ,
197
+ // A context to the current dir, which has a node_modules folder with workspace dependencies
198
+ context : __dirname ,
199
+ entry : {
200
+ // This format is a data: url combined with inline matchResource to obtain a virtual entry.
201
+ // See https://github.com/webpack/webpack/issues/6437#issuecomment-874466638
202
+ // See https://webpack.js.org/api/loaders/#inline-matchresource
203
+ [ entry . id ] : `./index.js!=!data:text/javascript,import ${ importNames } from '${ entry . import } ';console.log(foo);` ,
204
+ } ,
190
205
// TODO: 'browserslist:modern'
191
206
// See https://github.com/webpack/webpack/issues/14203
192
207
target : 'web' ,
0 commit comments