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

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

在react中使用sass時,引入.scss文件失效
嘗試不少方法無法解決,最終找到解決方法,但願能幫助正在坑裏掙扎的筒子~javascript

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

{
            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]', }, }
相關文章
相關標籤/搜索