react中怎么安装sass

互联网 20-11-26

react中安装sass的方法:首先安装【sass-loader】和n【ode-sass】依赖;然后打开react的webpack配置,并进行相关修改即可。

react中安装sass的方法:

一、安装sass-loader和node-sass依赖

npm install sass-loader node-sass --save-dev

二、打开react的webpack配置

node_modules/react-scripts/config/webpack.config.js

找到module下的rules,oneof数组中,然后找到最后一个配置,修改成如下的样子

            {               loader: require.resolve('file-loader'),               // Exclude `js` files to keep "css" loader working as it injects               // its runtime that would otherwise be processed through "file" loader.               // Also exclude `html` and `json` extensions so they get processed               // by webpacks internal loaders.               exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],               options: {                 name: 'static/media/[name].[hash:8].[ext]',               },             },             // ** STOP ** Are you adding a new loader?             // Make sure to add the new loader(s) before the "file" loader.           {             test:/\.scss$/,             loaders: ['style-loader', 'css-loader', 'sass-loader']           }

三、这样就可以愉快地使用scss文件了

相关免费学习推荐:javascript(视频)

以上就是react中怎么安装sass的详细内容,更多内容请关注技术你好其它相关文章!

来源链接:
免责声明:
1.资讯内容不构成投资建议,投资者应独立决策并自行承担风险
2.本文版权归属原作所有,仅代表作者本人观点,不代表本站的观点或立场
标签: sass
上一篇:php获取远程图片并下载保存到本地的方法分析 下一篇:react中如何引用json

相关资讯