1

While css files resolve just fine, in scss it simply won't resolve. Does anyone knows the solution? Sass-loader tells me to use 'resolve-url-loader', but I can't make it work. Im trying to add font-awesome. If i use the css version it works just fine (with file loader even copy fonts to dist) but with scss no.

Here is my prod config file.

webpack.production.js

const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');

const plugins = [
  new HtmlWebpackPlugin({
    inject: false,
    hash: true,
    template: __dirname + '/../src/app/Views/layouts/layout-template.phtml',
    filename: __dirname + '/../src/app/Views/layouts/layout.phtml'
  }),
  new MiniCssExtractPlugin({
    filename: 'css/[name].css',
    chunkFilename: 'css/[name].css',
  }),
];

module.exports = () => ({
  output: {
    publicPath: '/dist/',
  },
  optimization: {
    minimize: true,
    minimizer: [new TerserJSPlugin({
      terserOptions: {
        extractComments: 'all',
        compress: {
          drop_console: true
        }
      }
    }), new OptimizeCSSAssetsPlugin({})],
  },
  module: {
    rules: [
      {
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      },
      {
        test: /\.(sa|sc|c)ss$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
          },
          'css-loader?',
          'postcss-loader',
          'resolve-url-loader',
          'sass-loader'
        ],
      }
    ]
  },
  plugins
});

Thanks in advance. Cheers

grcoder
  • 324
  • 5
  • 17

2 Answers2

2

I figured it out. I needed to lower version of 'resolve-url-loader' to 2 and add sourceMap to sass-loader.

   {
    test: /\.(sa|sc|c)ss$/,
    use: [
      {
        loader: MiniCssExtractPlugin.loader,
      },
      'css-loader',
      'postcss-loader',
      'resolve-url-loader',
      'sass-loader?sourceMap'
    ],
  }
grcoder
  • 324
  • 5
  • 17
0

This config works with me :

replace this part object

{
    test: /\.scss$/,
    use: [
           MiniCssExtractPlugin.loader, 
          {
            loader: 'css-loader',
          }, 
          {
            loader: 'resolve-url-loader'
          }, 
          {
            loader: 'sass-loader',
          } 
         ]
}
Ayman Morsy
  • 1,279
  • 1
  • 10
  • 28