@@ -4,12 +4,25 @@ const Dotenv = require("dotenv-webpack");
44const HtmlWebpackPlugin = require ( "html-webpack-plugin" ) ;
55const WorkerPlugin = require ( "worker-plugin" ) ;
66const CopyWebpackPlugin = require ( "copy-webpack-plugin" ) ;
7+ const postcssImport = require ( "postcss-import" ) ;
8+ const postcssSimpleVars = require ( "postcss-simple-vars" ) ;
79
810let publicUrl = process . env . PUBLIC_URL || "/" ;
911if ( ! publicUrl . endsWith ( "/" ) ) {
1012 publicUrl += "/" ;
1113}
1214
15+ const scratchGuiInclude = [
16+ / n o d e _ m o d u l e s \/ s c r a t c h - g u i / ,
17+ / n o d e _ m o d u l e s \/ @ R a s p b e r r y P i F o u n d a t i o n \/ s c r a t c h - g u i / ,
18+ / s c r a t c h - e d i t o r \/ p a c k a g e s \/ s c r a t c h - g u i / ,
19+ ] ;
20+ const scratchVmInclude = [
21+ / n o d e _ m o d u l e s \/ @ s c r a t c h \/ s c r a t c h - v m / ,
22+ / n o d e _ m o d u l e s \/ s c r a t c h - v m / ,
23+ / s c r a t c h - e d i t o r \/ p a c k a g e s \/ s c r a t c h - v m / ,
24+ ] ;
25+
1326module . exports = {
1427 entry : {
1528 "web-component" : path . resolve ( __dirname , "./src/web-component.js" ) ,
@@ -20,8 +33,7 @@ module.exports = {
2033 {
2134 test : / \. ( t s | t s x ) $ / ,
2235 include : [
23- / n o d e _ m o d u l e s \/ s c r a t c h - g u i / ,
24- / n o d e _ m o d u l e s \/ @ R a s p b e r r y P i F o u n d a t i o n \/ s c r a t c h - g u i / ,
36+ ...scratchGuiInclude ,
2537 / n o d e _ m o d u l e s \/ @ s c r a t c h / , // Include @scratch packages
2638 / n o d e _ m o d u l e s \/ s c r a t c h - p a i n t / , // Include scratch-paint
2739 ] ,
@@ -85,6 +97,45 @@ module.exports = {
8597 } ,
8698 {
8799 test : / \. c s s $ / ,
100+ include : scratchGuiInclude ,
101+ use : [
102+ {
103+ loader : "style-loader" ,
104+ options : {
105+ insert : function insertAtShadowRoot ( element ) {
106+ var root = window . __editorShadowRoot ;
107+ if ( root && root . appendChild ) {
108+ root . appendChild ( element ) ;
109+ } else {
110+ document . head . appendChild ( element ) ;
111+ }
112+ } ,
113+ } ,
114+ } ,
115+ {
116+ loader : "css-loader" ,
117+ options : {
118+ importLoaders : 1 ,
119+ modules : {
120+ auto : ( resourcePath ) => ! resourcePath . endsWith ( ".raw.css" ) ,
121+ localIdentName : "[name]_[local]_[hash:base64:5]" , // Match scratch-gui module naming
122+ exportLocalsConvention : "camelCase" ,
123+ } ,
124+ } ,
125+ } ,
126+ {
127+ loader : "postcss-loader" ,
128+ options : {
129+ postcssOptions : {
130+ plugins : [ postcssImport ( ) , postcssSimpleVars ( ) ] ,
131+ } ,
132+ } ,
133+ } ,
134+ ] ,
135+ } ,
136+ {
137+ test : / \. c s s $ / ,
138+ exclude : scratchGuiInclude ,
88139 use : [
89140 "to-string-loader" ,
90141 {
@@ -160,23 +211,21 @@ module.exports = {
160211 } ,
161212 {
162213 test : / \. m p 3 $ / ,
163- include : / n o d e _ m o d u l e s \/ @ R a s p b e r r y P i F o u n d a t i o n \/ s c r a t c h - g u i / ,
164214 type : "asset/resource" ,
165215 generator : {
166216 filename : "static/media/[name].[hash][ext]" ,
167217 } ,
168218 } ,
169219 {
170220 test : / \. w a v $ / ,
171- include : / n o d e _ m o d u l e s \/ @ R a s p b e r r y P i F o u n d a t i o n \/ s c r a t c h - g u i / ,
172221 type : "asset/resource" ,
173222 generator : {
174223 filename : "static/media/[name].[hash][ext]" ,
175224 } ,
176225 } ,
177226 {
178227 test : / \. ( p n g | j p g | j p e g | g i f ) $ / ,
179- include : / n o d e _ m o d u l e s \/ @ R a s p b e r r y P i F o u n d a t i o n \/ s c r a t c h - g u i / ,
228+ include : scratchGuiInclude ,
180229 type : "asset/resource" ,
181230 generator : {
182231 filename : "static/media/[name].[hash][ext]" ,
@@ -185,7 +234,6 @@ module.exports = {
185234 // Handle arrayBuffer imports specifically
186235 {
187236 test : / \. ( m p 3 | w a v ) $ / ,
188- include : / n o d e _ m o d u l e s \/ @ R a s p b e r r y P i F o u n d a t i o n \/ s c r a t c h - g u i / ,
189237 resourceQuery : / a r r a y B u f f e r / ,
190238 type : "asset/resource" ,
191239 generator : {
@@ -194,7 +242,7 @@ module.exports = {
194242 } ,
195243 {
196244 test : / \. h e x $ / ,
197- include : / n o d e _ m o d u l e s \/ @ R a s p b e r r y P i F o u n d a t i o n \/ s c r a t c h - g u i / ,
245+ include : scratchGuiInclude ,
198246 type : "asset/resource" ,
199247 generator : {
200248 filename : "static/firmware/[name].[hash][ext]" ,
@@ -204,6 +252,15 @@ module.exports = {
204252 } ,
205253 resolve : {
206254 extensions : [ ".*" , ".js" , ".jsx" , ".css" , ".ts" , ".tsx" ] , // Add .ts and .tsx
255+ alias : {
256+ "@RaspberryPiFoundation/scratch-gui" : path . resolve (
257+ __dirname ,
258+ "../scratch-editor/packages/scratch-gui/src" ,
259+ ) ,
260+ react : path . resolve ( __dirname , "node_modules/react" ) ,
261+ "react-dom" : path . resolve ( __dirname , "node_modules/react-dom" ) ,
262+ "react-redux" : path . resolve ( __dirname , "node_modules/react-redux" ) ,
263+ } ,
207264 fallback : {
208265 stream : require . resolve ( "stream-browserify" ) ,
209266 assert : require . resolve ( "assert" ) ,
@@ -224,6 +281,9 @@ module.exports = {
224281 port : 3011 ,
225282 liveReload : true ,
226283 hot : false ,
284+ client : {
285+ overlay : false ,
286+ } ,
227287 static : {
228288 directory : path . join ( __dirname , "public" ) ,
229289 } ,
0 commit comments