From 36ec35eff84c80d48e0b696439b1874594291e90 Mon Sep 17 00:00:00 2001 From: Pierre de la Martiniere Date: Tue, 1 Nov 2022 16:36:30 +0100 Subject: [PATCH] Better fix for next 13.0.1 --- src/next-transpile-modules.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/next-transpile-modules.js b/src/next-transpile-modules.js index 817fccf..b86ba61 100644 --- a/src/next-transpile-modules.js +++ b/src/next-transpile-modules.js @@ -197,6 +197,33 @@ const withTmInitializer = (modules = [], options = {}) => { // 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)$/) + ); + + // backwards compatibility with Next.js 13.0 (broke in 13.0.1) + // https://github.com/vercel/next.js/pull/42106/files + if (nextCssLoader && nextCssLoader.issuer != null) { + nextCssLoader.issuer.or = nextCssLoader.issuer.and ? nextCssLoader.issuer.and.concat(matcher) : matcher; + delete nextCssLoader.issuer.not; + delete nextCssLoader.issuer.and; + } + + // backwards compatibility with Next.js 13.0 (broke in 13.0.1) + // https://github.com/vercel/next.js/pull/42106/files + if (nextSassLoader && nextSassLoader.issuer != null) { + nextSassLoader.issuer.or = nextSassLoader.issuer.and ? nextSassLoader.issuer.and.concat(matcher) : matcher; + delete nextSassLoader.issuer.not; + delete nextSassLoader.issuer.and; + } + } + // Add support for Global CSS imports in transpiled modules if (nextCssLoaders) { const nextGlobalCssLoader = nextCssLoaders.oneOf.find(