Sha256: 640d34aaa72de6d38bbf3283c710ad9ac5bcdd6f3accf42aa0bf5c2d24f9bf0b

Contents?: true

Size: 1.51 KB

Versions: 12

Compression:

Stored size: 1.51 KB

Contents

const path = require("path");
const miniCssExtractPlugin = require("mini-css-extract-plugin");
const { inliningCss } = require("@rails/webpacker");

const overrideSassRule = (modifyConfig) => {
  const sassLoaderPath = path.resolve(__dirname, "loaders/decidim-sass-loader") // eslint-disable-line no-undef

  const sassRule = modifyConfig.module.rules.find(
    (rule) => rule.test.toString() === "/\\.(scss|sass)(\\.erb)?$/i"
  );
  if (sassRule) {
    const existingLoader = sassRule.use.find((use) => {
      return (typeof use === "object") && use.loader.match(/sass-loader/);
    });
    if (existingLoader) {
      existingLoader.loader = sassLoaderPath;
    } else {
      sassRule.use.push({ loader: sassLoaderPath });
    }
  } else {
    // Add the sass rule
    let baseLoader = "style-loader";
    if (!inliningCss) {
      baseLoader = miniCssExtractPlugin.loader;
    }

    modifyConfig.module.rules.push({
      test: /\.(scss|sass)(\.erb)?$/i,
      use: [
        baseLoader,
        {
          loader: require.resolve("css-loader"),
          options: {
            sourceMap: true,
            importLoaders: 2
          }
        },
        {
          loader: "postcss-loader",
          options: { sourceMap: true }
        },
        {
          loader: sassLoaderPath
        }
      ]
    })
  }

  return modifyConfig;
}

// Since all modifiers are functions, we can use a reduce clause to apply all them
module.exports = (originalConfig) => [overrideSassRule].reduce((acc, modifier) => modifier(acc), originalConfig)

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-0.27.9 packages/webpacker/src/override-config.js
decidim-0.27.8 packages/webpacker/src/override-config.js
decidim-0.27.7 packages/webpacker/src/override-config.js
decidim-0.27.6 packages/webpacker/src/override-config.js
decidim-0.27.5 packages/webpacker/src/override-config.js
decidim-0.27.4 packages/webpacker/src/override-config.js
decidim-0.27.3 packages/webpacker/src/override-config.js
decidim-0.27.2 packages/webpacker/src/override-config.js
decidim-0.27.1 packages/webpacker/src/override-config.js
decidim-0.27.0 packages/webpacker/src/override-config.js
decidim-0.27.0.rc2 packages/webpacker/src/override-config.js
decidim-0.27.0.rc1 packages/webpacker/src/override-config.js