闫晓明 發表於 2021-1-9 17:33:00

React + Sass

<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>&nbsp;Sass很多公司面试都喜欢问这个,今天就写一篇简单的sass安装+使用过程</strong></span><br><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>技术栈很简单,就React + Sass,本文着重讨论sass不整太多东西</strong></span></p>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>创建项目:<span style="color: rgba(255, 0, 0, 1)">create-react-app react-sass</span></strong></span></div>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>安装依赖:<span style="color: rgba(255, 0, 0, 1)">npm install --save-dev node-sass</span></strong></span></div>
<div>&nbsp;</div>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>create-react-app 创建的react项目默认就是支持Sass的,</strong></span></div>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>使用只要安装node-sass即可使用</strong></span></div>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>&nbsp;</strong></span></div>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>以上就是sass的安装过程,具体怎么用其实看官网跟着写就行了&nbsp;</strong></span></p>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>&nbsp;</strong></span></p>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>项目上使用:</strong></span></div>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><span style="font-family: Microsoft YaHei; font-size: 16px"><span style="font-family: Microsoft YaHei; font-size: 16px"><strong><img src="https://img2020.cnblogs.com/blog/1318601/202101/1318601-20210109174418806-763745733.png" alt="" loading="lazy"></strong></span></span></span>
<p>&nbsp;</p>
<p>&nbsp;<span style="font-family: Microsoft YaHei; font-size: 16px"><strong> <br></strong></span></p>

</div>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>页面效果</strong></span></p>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong><img src="https://img2020.cnblogs.com/blog/1318601/202101/1318601-20210109173216157-1301142075.png" alt="" loading="lazy"></strong></span></p>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>&nbsp;</strong></span></p>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>&nbsp;node-sass版本报错:</strong></span></p>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong><img src="https://img2020.cnblogs.com/blog/1318601/202101/1318601-20210109171936362-1578024652.png" alt="" loading="lazy"></strong></span>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>&nbsp;我的node版本跟node-sass不配合</strong></span></p>







</div>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>&nbsp;</strong></span></p>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>目前解决方案如下:</strong></span></div>
<div>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>查看node版本:node -v</strong></span></div>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong><img src="https://img2020.cnblogs.com/blog/1318601/202101/1318601-20210109172126699-1569347298.png" alt="" loading="lazy"></strong></span>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>&nbsp;</strong></span></p>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>去官网对比下版本号,不同node版本对应不同node-sass版本</strong></span></div>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>https://www.npmjs.com/package/node-sass</strong></span></div>












</div>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong><img src="https://img2020.cnblogs.com/blog/1318601/202101/1318601-20210109172147397-99297733.png" alt="" loading="lazy"></strong></span>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>&nbsp;然后安装对应的版本:npm install node-sass@对应的版本号</strong></span></p>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>&nbsp;</strong></span></div>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>比如我是node版本是12(有点老了。。)对应的就是4.12+</strong></span></div>
<div><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>所以我安装4.14.1版本:npm install node-sass@4.14.1</strong></span></div>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>&nbsp;</strong></span></p>












</div>












</div>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>最后说点什么:</strong></span><br><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>网上看文章感觉大家都喜欢聊一个技术的时候都下意识的扯到很多其他技术或者内容</strong></span><br><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>虽然拓展了技术范围但同时也容易造成核心技术被干扰,</strong></span><br><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>特别是小白完全被带晕了(小白:我只想学xx技术怎么大佬给我整那么多前置技术才能学我想要的xx技术(ಥ_ಥ)!!)</strong></span><br><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>所以我个人觉得聊一个技术的时候就尽量只说一个东西,别整太多胡里花哨,想拓展可以再写一篇文章专门聊嘛</strong></span></p>
<p><span style="font-family: Microsoft YaHei; font-size: 16px"><strong>&nbsp;</strong></span></p><br><br>
来源:https://www.cnblogs.com/konghaowei/p/14255634.html
頁: [1]
查看完整版本: React + Sass