Sha256: 645a0c83e8dee6b6477a12ccbd269144a34eaf644ab175bf388a764609048be0

Contents?: true

Size: 1.43 KB

Versions: 17

Compression:

Stored size: 1.43 KB

Contents

const { config } = require("@rails/webpacker");

const overrideSassRule = (modifyConfig) => {
  const sassRule = modifyConfig.module.rules.find(
    (rule) => rule.test.toString() === "/\\.(scss|sass)(\\.erb)?$/i"
  );
  if (!sassRule) {
    return modifyConfig;
  }

  const sassLoader = sassRule.use.find((use) => {
    return (typeof use === "object") && use.loader.match(/sass-loader/);
  });
  if (!sassLoader) {
    return modifyConfig;
  }

  const imports = config.stylesheet_imports;
  if (!imports) {
    return modifyConfig;
  }

  // Add the extra importer to the sass-loader to load the import statements for
  // Decidim modules.
  sassLoader.options.sassOptions.importer = [
    (url) => {
      const matches = url.match(/^!decidim-style-([^[]+)\[([^\]]+)\]$/);
      if (!matches) {
        return null;
      }

      const type = matches[1];
      const group = matches[2];
      if (!imports[type] || !imports[type][group]) {
        // If the group is not defined, return an empty configuration because
        // otherwise the importer would continue finding the asset through
        // paths which obviously fails.
        return { contents: "" };
      }

      const statements = imports[type][group].map((style) => `@import "${style}";`);

      return { contents: statements.join("\n") };
    }
  ];

  return modifyConfig;
}

module.exports = (originalConfig) => { // eslint-disable-line
  return overrideSassRule(originalConfig);
};

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
decidim-0.26.10 packages/webpacker/src/override-config.js
decidim-0.26.9 packages/webpacker/src/override-config.js
decidim-0.26.8 packages/webpacker/src/override-config.js
decidim-0.26.7 packages/webpacker/src/override-config.js
decidim-0.26.5 packages/webpacker/src/override-config.js
decidim-0.26.4 packages/webpacker/src/override-config.js
decidim-0.26.3 packages/webpacker/src/override-config.js
decidim-0.26.2 packages/webpacker/src/override-config.js
decidim-0.26.1 packages/webpacker/src/override-config.js
decidim-0.26.0 packages/webpacker/src/override-config.js
decidim-0.26.0.rc2 packages/webpacker/src/override-config.js
decidim-0.25.2 packages/webpacker/src/override-config.js
decidim-0.25.1 packages/webpacker/src/override-config.js
decidim-0.25.0 packages/webpacker/src/override-config.js
decidim-0.25.0.rc4 packages/webpacker/src/override-config.js
decidim-0.25.0.rc3 packages/webpacker/src/override-config.js
decidim-0.25.0.rc2 packages/webpacker/src/override-config.js