【已解決】React中配置Sass引入.scss文件無效


React中配置Sass引入.scss文件無效

在react中使用sass時,引入.scss文件失效
嘗試很多方法沒法解決,最終找到解決方法,希望能幫助正在坑里掙扎的筒子~

在node_modules文件夾下,找到react-scripts ==> config文件夾, 在該配置文件夾下找到 webpack.config.dev.jswebpack.config.prod.js
file-loader之前添加style-loader, css-loader, sass-loader
代碼如下:

          {
            test: /\.scss$/,
            loaders: ['style-loader', 'css-loader', 'sass-loader'],
          },
          // "file" loader makes sure those assets get served by WebpackDevServer.
          // When you `import` an asset, you get its (virtual) filename.
          // In production, they would get copied to the `build` folder.
          // This loader doesn't use a "test" so it will catch all modules
          // that fall through the other loaders.
          {
            // Exclude `js` files to keep "css" loader working as it injects
            // its runtime that would otherwise processed through "file" loader.
            // Also exclude `html` and `json` extensions so they get processed
            // by webpacks internal loaders.
            exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/],
            loader: require.resolve('file-loader'),
            options: {
              name: 'static/media/[name].[hash:8].[ext]',
            },
          }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM