如何在 dva 中使用 sass

Oct 26, 2016

安装 sass-loader 和 node-sass 之后,在 webpack.config.js 中

webpackConfig.module.loaders.forEach(function(loader, index) {

之上(其实只要在这个 function 里面都可以),添加以下代码:

webpackConfig.module.loaders.push({
  test: /\.module\.sass$/,
  loader: path.join(path.dirname(require.resolve('extract-text-webpack-plugin')), 'loader.js') + '?{"remove":true}!css?sourceMap&modules&localIdentName=[local]___[hash:base64:5]&-autoprefixer!' + 'postcss-loader!'+ 'sass-loader?sourceMap'
});

然后在

webpackConfig.module.loaders.forEach(function(loader, index) {

之下添加以下代码即可:

if (typeof loader.test === 'function' && loader.test.toString().indexOf('\\.sass$') > -1) {
  loader.include = /node_modules/;
  loader.test = /\.sass$/;
}
if (loader.test.toString() === '/\\.module\\.sass$/') {
  loader.exclude = /node_modules/;
  loader.test = /\.sass$/;
}

[back]