Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose css/sass defaultLoaders in config options. #24140

Closed
Izhaki opened this issue Apr 16, 2021 · 1 comment
Closed

Expose css/sass defaultLoaders in config options. #24140

Izhaki opened this issue Apr 16, 2021 · 1 comment

Comments

@Izhaki
Copy link

Izhaki commented Apr 16, 2021

Describe the feature you'd like to request

NextJS already exposes defaultLoaders.babel, which can be used as follows to allow transpilation of soures outside the baseDir (in Monorepos):

module.exports = withBundleAnalyzer({
  webpack: (config, options) => {
    // To allow transpiling aliases
    config.module.rules.push({
      test: /\.+(js|jsx|mjs|ts|tsx)$/,
      use: options.defaultLoaders.babel,
      include: Object.values(aliases),
    });

    return config;
  },
});

Given the built-in support for CSS/SCSS in NextJS, full support for monorepo setup will require to allow importing css/scss (in addition to js/ts) files from directories outside the baseDir.

The issue with current workaround

The current way next-transpile-modules does it, is horribly hacky (@martpie):

        // Support CSS modules + global in node_modules
        // TODO ask Next.js maintainer to expose the css-loader via defaultLoaders
        const nextCssLoaders = config.module.rules.find((rule) => typeof rule.oneOf === 'object');

        // .module.css
        if (nextCssLoaders) {
          const nextCssLoader = nextCssLoaders.oneOf.find(
            (rule) => rule.sideEffects === false && regexEqual(rule.test, /\.module\.css$/)
          );

          const nextSassLoader = nextCssLoaders.oneOf.find(
            (rule) => rule.sideEffects === false && regexEqual(rule.test, /\.module\.(scss|sass)$/)
          );

          if (nextCssLoader) {
            nextCssLoader.issuer.or = nextCssLoader.issuer.and ? nextCssLoader.issuer.and.concat(matcher) : matcher;
            delete nextCssLoader.issuer.not;
            delete nextCssLoader.issuer.and;
          } else {
            console.warn('next-transpile-modules - could not find default CSS rule, CSS imports may not work');
          }

          if (nextSassLoader) {
            nextSassLoader.issuer.or = nextSassLoader.issuer.and ? nextSassLoader.issuer.and.concat(matcher) : matcher;
            delete nextSassLoader.issuer.not;
            delete nextSassLoader.issuer.and;
          } else {
            console.warn('next-transpile-modules - could not find default SASS rule, SASS imports may not work');
          }
        }

Describe the solution you'd like

options.defaultLoaders.css
options.defaultLoaders.sass

Describe alternatives you've considered

@martpie
Copy link
Contributor

martpie commented Apr 16, 2021

Oh hell yes! 👍

@vercel vercel locked and limited conversation to collaborators Apr 16, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants