简体   繁体   English

向Vue项目添加SCSS支持

[英]Add SCSS support to Vue project

In my packages.json file by default I get: 默认情况下,在我的packages.json文件中,我得到:

"postcss": {
"plugins": {
  "autoprefixer": {}
}}

When I add <style lang='scss'> It doesn't compile like magic like it does for Typescript support. 当我添加<style lang='scss'>它不会像对Typescript支持那样神奇地进行编译。 I know I will need to specify some NPM package as devDependencies and specify something above in the postcss section to get scss to compile, but I can't find any documentation outside of webpack so I am lost. 我知道我需要将一些NPM包指定为devDependencies,并在postcss部分中指定上面的内容,以便编译scss,但是我在webpack之外找不到任何文档,所以我迷路了。

See https://vue-loader.vuejs.org/guide/pre-processors.html . 请参阅https://vue-loader.vuejs.org/guide/pre-processors.html

For example, to compile our <style> tag with SASS/SCSS: 例如,要使用SASS / SCSS编译<style>标签:

 npm install -D sass-loader node-sass 

In your webpack config: 在您的webpack配置中:

 module.exports = { module: { rules: [ // ... other rules omitted // this will apply to both plain `.scss` files // AND `<style lang="scss">` blocks in `.vue` files { test: /\\.scss$/, use: [ 'vue-style-loader', 'css-loader', 'sass-loader' ] } ] }, // plugin omitted } 

Now in addition to being able to import 'style.scss' , we can use SCSS in Vue components as well: 现在,除了能够import 'style.scss' ,我们还可以在Vue组件中使用SCSS:

 <style lang="scss"> /* write SCSS here */ </style> 

Any content inside the block will be processed by webpack as if it's inside a *.scss file. webpack将处理块中的任何内容,就像在*.scss文件中一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM