如果可以,请告诉我如何使用convert-sass命令进行转换;否则,也许有编译器能够完成这个任务吗?谢谢。
是的,sass-convert
接受一个递归参数。
如果你运行 sass-convert --help
命令,它会给出可用选项的列表。其中之一是:
-R, --recursive Convert all the files in a directory. Requires --from and --to.
因此,您的命令应该是这样的:
sass-convert -R my_sass_dir --from sass --to scss
sass-convert
,但我们可以通过安装已弃用的Ruby SASS来访问它 - gem install sass
。 - Jakub Zawiślakgem install sass
对我有用,你救了我的一天。 - Rafael López Doradogo to your project subfolder, under which all your styles sit (also, because you want to leave node_modules alone, do you?)
cd frontend/src
convert in place, as said (consider --indent 4
if that's your indentation style...)
sass-convert -R . --from scss --to sass --in-place
you almost certainly want to rename all those .scss files to .sass (details)
find . -name '*.scss' -exec sh -c 'mv "$0" "${0%.scss}.sass"'
In your .js or .jsx files, you want to adjust your import statements.
find . -name '*.jsx' -print0 | xargs -0 sed -i "s/'\.\(.*\)\.scss'/'.\1.sass'/g"
More specifically, only your local import statements, starting with a '.
', not your global imports, i.e. pointing to node_modules… right?
Testcase:
import './style.scss' // should change to .sass
import './bar.scss' // should change to .sass
import 'slick-carousel/slick/slick.scss' // leave me alone!
剩余的陷阱包括:
webpack.config
(加载器!),grunt或gulpfile,仍然匹配.sass
convert-sass --help
并没有提供如何做到这一点的信息,你最好的选择就是询问“我该如何在终端上递归地运行一个命令来处理文件目录”。 - cimmanon