From 940ddb4f054bccb506badab6c081d0e61fe8ab83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corne=CC=81=20Dorrestijn?= Date: Tue, 25 Oct 2022 21:04:40 +0200 Subject: [PATCH] Added support for Next.JS 13 with appDir enabled --- src/next-transpile-modules.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/next-transpile-modules.js b/src/next-transpile-modules.js index 164350e..1ac9a4e 100644 --- a/src/next-transpile-modules.js +++ b/src/next-transpile-modules.js @@ -226,8 +226,12 @@ const withTmInitializer = (modules = [], options = {}) => { ); if (nextGlobalCssLoader) { - nextGlobalCssLoader.issuer = { or: [matcher, nextGlobalCssLoader.issuer] }; - nextGlobalCssLoader.include = { or: [...modulesPaths, nextGlobalCssLoader.include] }; + nextGlobalCssLoader.issuer = { + or: nextGlobalCssLoader.issuer ? [matcher, nextGlobalCssLoader.issuer] : [matcher], + }; + nextGlobalCssLoader.include = { + or: nextGlobalCssLoader.include ? [...modulesPaths, nextGlobalCssLoader.include] : modulesPaths, + }; } else if (!options.isServer) { // Note that Next.js ignores global CSS imports on the server console.warn('next-transpile-modules - could not find default CSS rule, global CSS imports may not work'); @@ -240,7 +244,9 @@ const withTmInitializer = (modules = [], options = {}) => { // FIXME: SASS works only when using a custom _app.js file. // See https://github.com/vercel/next.js/blob/24c3929ec46edfef8fb7462a17edc767a90b5d2b/packages/next/build/webpack/config/blocks/css/index.ts#L211 if (nextGlobalSassLoader) { - nextGlobalSassLoader.issuer = { or: [matcher, nextGlobalSassLoader.issuer] }; + nextGlobalSassLoader.issuer = { + or: nextGlobalSassLoader.issuer ? [matcher, nextGlobalSassLoader.issuer] : [matcher], + }; } else if (!options.isServer) { // Note that Next.js ignores global SASS imports on the server console.info('next-transpile-modules - global SASS imports only work with a custom _app.js file');