How can I specify a resource root for SCSS includes in my Webpack sass-loader config?

假装没事ソ 提交于 2019-12-12 17:36:59

问题


Say I have something like:

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

in my webpack config and I have a app/ sub folder with all my SCSS and JS files in.

Currently to import an SCSS partial I have to @import 'app/whatever/my_partial'; for it to be recognised.

How can I set the loader to treat app/ as a resource root for these files so I can just say @import 'whatever/my_partial' ?

This is with Webpack 2.x btw.

Any help from you clever people much appreciated!


回答1:


You can add app/ to the includePaths option in the sass-loader. Your .scss rules has to be changed to:

{
  test: /\.scss$/,
  exclude: /node_modules/,
  use: [
    'style-loader',
    'css-loader',
    {
      loader: 'sass-loader',
      options: {
        includePaths: [path.resolve(process.cwd(), 'app')]
      }
    }
  ]
}


来源:https://stackoverflow.com/questions/43544601/how-can-i-specify-a-resource-root-for-scss-includes-in-my-webpack-sass-loader-co

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