From 610297a65b6831d388fa0dc0e933ebd741f14461 Mon Sep 17 00:00:00 2001 From: Alexander Khadisov Date: Mon, 17 Feb 2020 15:36:46 +0300 Subject: [PATCH 1/2] feature: support experimental .sass\.scss --- src/next-transpile-modules.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/next-transpile-modules.js b/src/next-transpile-modules.js index 68b7f90..832d592 100644 --- a/src/next-transpile-modules.js +++ b/src/next-transpile-modules.js @@ -87,20 +87,28 @@ const withTmInitializer = (transpileModules = []) => { // 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 + // .module.css and .module.css if (nextCssLoaders) { const nextCssLoader = nextCssLoaders.oneOf.find( (rule) => rule.sideEffects === false && regexEqual(rule.test, /\.module\.css$/) ); - if (nextCssLoader) { nextCssLoader.issuer.include = nextCssLoader.issuer.include.concat(includes); nextCssLoader.issuer.exclude = excludes; } + const nextSassLoader = nextCssLoaders.oneOf.find( + (rule) => rule.sideEffects === false && regexEqual(rule.test, /\.module\.(scss|sass)$/) + ); + + if (nextSassLoader) { + nextSassLoader.issuer.include = nextSassLoader.issuer.include.concat(includes); + nextSassLoader.issuer.exclude = excludes; + } + // Hack our way to disable errors on node_modules CSS modules const nextErrorCssLoader = nextCssLoaders.oneOf.find( - (rule) => rule.use && rule.use.loader === 'error-loader' && regexEqual(rule.test, /\.module\.css$/) + (rule) => rule.use && rule.use.loader === 'error-loader' && (Array.isArray(rule.test) ? regexEqual(rule.test[0], /\.module\.css$/) : regexEqual(rule.test, /\.module\.css$/)) ); if (nextErrorCssLoader) { @@ -108,11 +116,6 @@ const withTmInitializer = (transpileModules = []) => { } } - // Overload the Webpack config if it was already overloaded - if (typeof nextConfig.webpack === 'function') { - return nextConfig.webpack(config, options); - } - return config; }, From 63a72c927225eab3dcaa7e8610b7e798c4c2a42a Mon Sep 17 00:00:00 2001 From: Alexander Khadisov Date: Tue, 18 Feb 2020 10:10:41 +0300 Subject: [PATCH 2/2] feature: support experimental .sass\.scss --- src/next-transpile-modules.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/next-transpile-modules.js b/src/next-transpile-modules.js index 832d592..593bbf0 100644 --- a/src/next-transpile-modules.js +++ b/src/next-transpile-modules.js @@ -87,7 +87,7 @@ const withTmInitializer = (transpileModules = []) => { // 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 and .module.css + // .module.css and .module.sass/.module.scss if (nextCssLoaders) { const nextCssLoader = nextCssLoaders.oneOf.find( (rule) => rule.sideEffects === false && regexEqual(rule.test, /\.module\.css$/) @@ -114,6 +114,12 @@ const withTmInitializer = (transpileModules = []) => { if (nextErrorCssLoader) { nextErrorCssLoader.exclude = includes; } + + // Overload the Webpack config if it was already overloaded + if (typeof nextConfig.webpack === 'function') { + return nextConfig.webpack(config, options); + } + } return config;