先下载stylus相关包
npm install stylus stylus-loader --save-dev
然后显示隐藏的相关配置文件
npm run eject
如果有你使用了git还会报错,所以需要在项目目录执行一下
git add .
git commit -m "初始化项目(备注)"
然后在config/webpack.config.js里添加以下内容(前面css/cass都是自带的,脚手架搭起来的都有)
const stylusRegex = /\.styl|stylus$/;
{
test: stylusRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction && shouldUseSourceMap,
},
'stylus-loader'
)
},
然后就可以把css文件的后缀改为.styl了
但是改完后会报错 typeerror this.getoptions is not a function
这是因为stylus-loader版本与stylus版本不匹配
修改package.json中stylus与stylus-loader版本号,然后重新安装依赖,执行npm i
或者卸载stylus-loader,npm uninstall stylus-loader
然后重新安装指定版本npm uninstall stylus-loader@3.0.1 --save-dev