From 8cc11a8cd99a33e5b3c81a37e69a38bab6524538 Mon Sep 17 00:00:00 2001 From: cap-Bernardito Date: Mon, 13 Jul 2020 16:41:26 +0300 Subject: [PATCH] refactor: enables icss only when enable modules --- src/index.js | 33 +++++++++++++++++---------------- test/icss.test.js | 4 +++- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/index.js b/src/index.js index 1910ea27..bc98fbba 100644 --- a/src/index.js +++ b/src/index.js @@ -35,27 +35,28 @@ export default function loader(content, map, meta) { const sourceMap = options.sourceMap || false; const plugins = []; - if (shouldUseModulesPlugins(options.modules, this.resourcePath)) { - plugins.push(...getModulesPlugins(options, this)); - } - const exportType = options.onlyLocals ? 'locals' : 'full'; const preRequester = getPreRequester(this); const urlHandler = (url) => stringifyRequest(this, preRequester(options.importLoaders) + url); - const icssResolver = this.getResolve({ - mainFields: ['css', 'style', 'main', '...'], - mainFiles: ['index', '...'], - }); - plugins.push( - icssParser({ - context: this.context, - rootContext: this.rootContext, - resolver: icssResolver, - urlHandler, - }) - ); + if (shouldUseModulesPlugins(options.modules, this.resourcePath)) { + plugins.push(...getModulesPlugins(options, this)); + + const icssResolver = this.getResolve({ + mainFields: ['css', 'style', 'main', '...'], + mainFiles: ['index', '...'], + }); + + plugins.push( + icssParser({ + context: this.context, + rootContext: this.rootContext, + resolver: icssResolver, + urlHandler, + }) + ); + } if (options.import !== false && exportType === 'full') { const resolver = this.getResolve({ diff --git a/test/icss.test.js b/test/icss.test.js index 97a30650..a2963307 100644 --- a/test/icss.test.js +++ b/test/icss.test.js @@ -16,7 +16,9 @@ const testCases = fs.readdirSync(testCasesPath); describe('ICSS', () => { testCases.forEach((name) => { it(`show work with the case "${name}"`, async () => { - const compiler = getCompiler(`./icss/tests-cases/${name}/source.js`); + const compiler = getCompiler(`./icss/tests-cases/${name}/source.js`, { + modules: 'global', + }); const stats = await compile(compiler); expect(