Why am I not being able to compile SASS with Webpack?

杀马特。学长 韩版系。学妹 提交于 2019-11-30 03:27:36

The reason this is happening, is because Vue automatically generates loader configurations for CSS, SASS/SCSS, Stylus.

(See projectRoot/build/utils.js lines ~10 through ~50)

So you're seeing the error because you have a webpack loader that is attempting to import the file and then Vue is attempting to import the (already loaded) file. So you can think of your loader chain as sass -> css -> style -> sass -> css -> vue-style

In order to resolve this issue you have to get rid of the loader that you added:

{
  test: /\.scss$/,
  loaders: ['style', 'css', 'sass']
},

and just rely on the provided loader.

You can load your stylesheet in one of two ways:

NOTE: You MUST use scss instead of sass, as sass will attempt to parse your stylesheet using the indented syntax instead of the bracket syntax.

1:

<style lang="scss">
  @import './styles/main.scss
</style>

2:

<style src="./styles/main.scss"></style>

Both of these will import the stylesheet, the latter just prevents you from adding any additional styling to the component.

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