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

后端 未结 1 1712
醉酒成梦
醉酒成梦 2020-12-14 01:35

I have the following modules in my Webpack config:

module: {
    preLoaders: [
      {
        test: /\\.vue$/,
        loader: \'eslint\',
        include:          


        
相关标签:
1条回答
  • 2020-12-14 01:59

    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.

    0 讨论(0)
提交回复
热议问题