// This Webpack is only for building Sass (*.scss) to CSS.
const path = require('path');

// This plugin extracts CSS into separate files.
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

// This plugin removes empty scripts generated by Webpack.
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');

// input file: src/scss/style.scss
// output file: wwwroot/styles/style.css

module.exports = {
  entry: {
    style: './src/scss/style',
  },
  mode: 'development',
  output: {
    path: path.resolve(__dirname, 'wwwroot/styles'), // An output dir must be an absolute path.
    filename: '[name].js',
  },
  resolve: {
    extensions: ['.scss']
  },
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: [
          // Extract to CSS file
          MiniCssExtractPlugin.loader,
          // Translates CSS to CommonJS and ignore solving URL of images
          {
            loader: 'css-loader',
            options: {
              // Set to false, css-loader will not parse any paths specified in url or image-set.
              // For more details, please refer to https://webpack.js.org/loaders/css-loader/#url.
              url: false
            }
          },
          // Compiles Sass to CSS
          'sass-loader',
        ],
        exclude: /node_modules/,
      },
    ]// End rules
  },
  plugins: [
    new RemoveEmptyScriptsPlugin({ verbose: true }),
    new MiniCssExtractPlugin({
      // Configure the output of CSS.
      // It is relative to output dir. Only relative path works, absolute path does not work.
      filename: '[name].css',
    }),
  ],
};
