@@ -21,6 +21,16 @@ const publicPath = '/';
2121const publicUrl = '' ;
2222// Get environment variables to inject into our app.
2323const env = getClientEnvironment ( publicUrl ) ;
24+ const getSassLoader = ( options = { } ) => ( {
25+ loader : require . resolve ( 'sass-loader' ) ,
26+ options : {
27+ ...options ,
28+ sassOptions : {
29+ ...( options . sassOptions || { } ) ,
30+ silenceDeprecations : [ 'legacy-js-api' ] ,
31+ } ,
32+ } ,
33+ } ) ;
2434
2535// This is the development configuration.
2636// It is focused on developer experience and fast rebuilds.
@@ -88,6 +98,13 @@ module.exports = {
8898 // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
8999 'react-native' : 'react-native-web' ,
90100 } ,
101+ fallback : {
102+ dgram : false ,
103+ fs : false ,
104+ net : false ,
105+ tls : false ,
106+ child_process : false ,
107+ } ,
91108 plugins : [
92109 // Prevents users from importing files from outside of src/ (or node_modules/).
93110 // This often causes confusion because we only process files within src/ with babel.
@@ -150,7 +167,7 @@ module.exports = {
150167 } ,
151168 {
152169 test : / \. m o d u l e \. s ( a | c ) s s $ / ,
153- loader : [
170+ use : [
154171 require . resolve ( 'style-loader' ) ,
155172 // isDevelopment ? 'style-loader' : MiniCssExtractPlugin.loader,
156173 {
@@ -164,10 +181,9 @@ module.exports = {
164181 } ,
165182 } ,
166183 {
167- loader : require . resolve ( 'sass-loader' ) ,
168- options : {
184+ ...getSassLoader ( {
169185 sourceMap : true ,
170- } ,
186+ } ) ,
171187 } ,
172188 ] ,
173189 } ,
@@ -177,7 +193,7 @@ module.exports = {
177193 use : [
178194 'style-loader' , // creates style nodes from JS strings
179195 'css-loader' , // translates CSS into CommonJS
180- 'sass-loader' , // compiles Sass to CSS, using Node Sass by default
196+ getSassLoader ( ) , // compiles Sass to CSS
181197 ] ,
182198 } ,
183199 // "postcss" loader applies autoprefixer to our CSS.
@@ -217,20 +233,18 @@ module.exports = {
217233 } ,
218234 ] ,
219235 } ,
220- // "file" loader makes sure those assets get served by WebpackDevServer .
236+ // Webpack 5 asset modules emit files directly without file-loader .
221237 // When you `import` an asset, you get its (virtual) filename.
222238 // In production, they would get copied to the `build` folder.
223- // This loader doesn't use a "test" so it will catch all modules
224- // that fall through the other loaders.
225239 {
226240 // Exclude `js` files to keep "css" loader working as it injects
227- // its runtime that would otherwise processed through "file" loader .
241+ // its runtime that would otherwise be processed through the asset rule .
228242 // Also exclude `html` and `json` extensions so they get processed
229- // by webpacks internal loaders.
243+ // by webpack's internal loaders.
230244 exclude : [ / \. ( j s | j s x | m j s ) $ / , / \. h t m l $ / , / \. j s o n $ / ] ,
231- loader : require . resolve ( 'file-loader' ) ,
232- options : {
233- name : 'static/media/[name].[hash:8]. [ext]' ,
245+ type : 'asset/resource' ,
246+ generator : {
247+ filename : 'static/media/[name].[hash:8][ext]' ,
234248 } ,
235249 } ,
236250 ] ,
@@ -266,7 +280,10 @@ module.exports = {
266280 // solution that requires the user to opt into importing specific locales.
267281 // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
268282 // You can remove this if you don't use Moment.js:
269- new webpack . IgnorePlugin ( / ^ \. \/ l o c a l e $ / , / m o m e n t $ / ) ,
283+ new webpack . IgnorePlugin ( {
284+ resourceRegExp : / ^ \. \/ l o c a l e $ / ,
285+ contextRegExp : / m o m e n t $ / ,
286+ } ) ,
270287 // Perform type checking and linting in a separate process to speed up compilation
271288 new ForkTsCheckerWebpackPlugin ( {
272289 async : false ,
@@ -275,15 +292,6 @@ module.exports = {
275292 tslint : paths . appTsLint ,
276293 } ) ,
277294 ] ,
278- // Some libraries import Node modules but don't use them in the browser.
279- // Tell Webpack to provide empty mocks for them so importing them works.
280- node : {
281- dgram : 'empty' ,
282- fs : 'empty' ,
283- net : 'empty' ,
284- tls : 'empty' ,
285- child_process : 'empty' ,
286- } ,
287295 // Turn off performance hints during development because we don't do any
288296 // splitting or minification in interest of speed. These warnings become
289297 // cumbersome.
0 commit comments