How to use SASS / SCSS with latest vue-cli starter project?

落爺英雄遲暮 提交于 2019-11-27 10:20:58

问题


I need to use SASS or SCSS in my project.

I used the vue-cli to make the latest version of a starter project.

Anyone had any success in making sass/scss work in the newest starter project with webpack?


回答1:


  1. you install the necessary dependencies

    npm install -D node-sass sass-loader

  2. for global styles, simply import the file into main.js:

    import './styles/my-styles.scss'

  3. in .vue files, add the lang to the <style> element.

    <style lang="scss">

If using webstorm:

<style lang="scss" rel="stylesheet/scss">




回答2:


As Latest documentation of @vue/cli-service": "^3.9.0", first need to install two npm dev dependencies i.e. sass, sass-loader

Sass

npm install -D sass-loader sass

yarn add --dev sass-loader sass

Then you can import the corresponding file types, or use them in *.vue files with:

<style lang="scss">
  $color: red;
</style>

Refer to latest documentation here




回答3:


Add this in your package.json in scripts and run

"compile:sass": "node-sass 'your main scss file location' 'your compiled css file location' -w"

Please make sure that node-sass and sass-loader are added properly.

And then in you App.vue file add this, then run

<style lang="scss">

    @import 'your compiled css file location';

</style>

This works for me.

Thanks



来源:https://stackoverflow.com/questions/44019469/how-to-use-sass-scss-with-latest-vue-cli-starter-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!