From 544786e2d954776a3d24fbe8f1e1a9f702f66ad3 Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Wed, 23 Jun 2021 16:21:03 +0200 Subject: [PATCH] Fix duplicated css imports see webpack-contrib/sass-loader#972 --- webpack/base.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/webpack/base.js b/webpack/base.js index f21924b762c..3e9f6e9d791 100644 --- a/webpack/base.js +++ b/webpack/base.js @@ -31,6 +31,18 @@ function _resolveTheme(rootPath, indicoClientPath, filePath) { return path.resolve(rootPath, filePath); } +function _importOnce(...args) { + // Due to https://github.com/webpack-contrib/sass-loader/pull/958/files we need to + // use a different context for the importOnce plugin in order to keep the cache + // between calls to this function. + // Using a global one might work as well but like this it's scoped with the same + // lifetime which we had before the sass-loader update as `options` is cloned at + // the same time the object previously used in `this` was created (`context` in + // `getOptions`). + this.options._ctx = this.options._ctx || {options: this.options}; + return importOnce.apply(this.options._ctx, args); +} + export function getThemeEntryPoints(config, prefix) { const themes = config.themes; const indicoClientPath = path.join( @@ -199,7 +211,7 @@ export function webpackDefaults(env, config, bundles, isPlugin = false) { sassOptions: { includePaths: [scssIncludePath], outputStyle: 'compact', - importer: [sassResolver, importOnce], + importer: [sassResolver, _importOnce], }, }, },