1+ const NodePolyfillPlugin = require ( "node-polyfill-webpack-plugin" ) ;
2+ const path = require ( "path" ) ;
3+
4+ module . exports = {
5+ webpack : {
6+ plugins : {
7+ add : [ new NodePolyfillPlugin ( ) ]
8+ } ,
9+ configure : ( webpackConfig ) => {
10+ // Remove the ModuleScopePlugin which restricts imports to src/
11+ webpackConfig . resolve . plugins = webpackConfig . resolve . plugins . filter (
12+ plugin => plugin . constructor . name !== 'ModuleScopePlugin'
13+ ) ;
14+
15+ // Find and update the babel-loader rule to include workspace packages
16+ const babelRule = webpackConfig . module . rules . find ( rule =>
17+ rule . oneOf && Array . isArray ( rule . oneOf )
18+ ) ;
19+
20+ if ( babelRule ) {
21+ const jsRule = babelRule . oneOf . find ( rule =>
22+ rule . test && rule . test . toString ( ) . includes ( 'jsx' )
23+ ) ;
24+
25+ if ( jsRule ) {
26+ // Extend the JS/JSX rule to include workspace packages
27+ jsRule . include = [
28+ jsRule . include ,
29+ path . resolve ( __dirname , "../../packages/skia/src" )
30+ ] . filter ( Boolean ) ;
31+ }
32+ }
33+
34+ // Add aliases for React Native modules
35+ webpackConfig . resolve . alias = {
36+ ...webpackConfig . resolve . alias ,
37+ "react-native$" : "react-native-web" ,
38+ "react-native-reanimated" : "react-native-reanimated/lib/module/web" ,
39+ "react-native/Libraries/Image/AssetRegistry" : "react-native-web/dist/modules/AssetRegistry" ,
40+ "@shopify/react-native-skia$" : path . resolve ( __dirname , "../../packages/skia/src/index.ts" ) ,
41+ "@shopify/react-native-skia/src/web" : path . resolve ( __dirname , "../../packages/skia/src/web/index.ts" )
42+ } ;
43+
44+ // Ensure canvaskit.wasm is accessible
45+ webpackConfig . resolve . fallback = {
46+ ...webpackConfig . resolve . fallback ,
47+ fs : false ,
48+ path : require . resolve ( "path-browserify" ) ,
49+ "react-native-reanimated" : false ,
50+ "react-native-reanimated/package.json" : false ,
51+ } ;
52+
53+ return webpackConfig ;
54+ }
55+ }
56+ } ;
0 commit comments