Skip to content

Commit

Permalink
Better fix for next 13.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre de la Martiniere committed Nov 1, 2022
1 parent 9a11e49 commit 36ec35e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/next-transpile-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 36ec35e

Please sign in to comment.