From 9c2aaf76826e4e107e5c97ac6ca72188432243f6 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Mon, 24 May 2021 16:53:11 +0300 Subject: [PATCH] refactor: code --- src/index.js | 11 +++++++++-- src/utils.js | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 3b69316a..e9fe4f02 100644 --- a/src/index.js +++ b/src/index.js @@ -111,7 +111,9 @@ export default async function loader(content, map, meta) { const icssPluginImports = []; const icssPluginApi = []; - if (shouldUseIcssPlugin(options)) { + const needToUseIcssPlugin = shouldUseIcssPlugin(options); + + if (needToUseIcssPlugin) { const icssResolver = this.getResolve({ conditionNames: ["style"], extensions: [], @@ -211,7 +213,12 @@ export default async function loader(content, map, meta) { const importCode = getImportCode(imports, options); const moduleCode = getModuleCode(result, api, replacements, options, this); - const exportCode = getExportCode(exports, replacements, options); + const exportCode = getExportCode( + exports, + replacements, + needToUseIcssPlugin, + options + ); callback(null, `${importCode}${moduleCode}${exportCode}`); } diff --git a/src/utils.js b/src/utils.js index e1a819ad..883ae857 100644 --- a/src/utils.js +++ b/src/utils.js @@ -770,10 +770,10 @@ function dashesCamelCase(str) { ); } -function getExportCode(exports, replacements, options) { +function getExportCode(exports, replacements, needToUseIcssPlugin, options) { let code = "// Exports\n"; - if (!shouldUseIcssPlugin(options)) { + if (!needToUseIcssPlugin) { code += `${ options.esModule ? "export default" : "module.exports =" } ___CSS_LOADER_EXPORT___;\n`;