diff --git a/src/options.json b/src/options.json index 4ad07b19..ba1448e4 100644 --- a/src/options.json +++ b/src/options.json @@ -55,7 +55,14 @@ ] }, "importLoaders": { - "type": "number" + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number" + } + ] }, "exportOnlyLocals": { "type": "boolean" diff --git a/test/__snapshots__/errors.test.js.snap b/test/__snapshots__/errors.test.js.snap index 5660fd3b..14050475 100644 --- a/test/__snapshots__/errors.test.js.snap +++ b/test/__snapshots__/errors.test.js.snap @@ -97,7 +97,9 @@ options.camelCase should match some schema in anyOf exports[`validation 13`] = ` "CSS Loader Invalid Options +options.importLoaders should be boolean options.importLoaders should be number +options.importLoaders should match some schema in anyOf " `; diff --git a/test/__snapshots__/modules-option.test.js.snap b/test/__snapshots__/modules-option.test.js.snap index ec9aa4c1..cfbbe580 100644 --- a/test/__snapshots__/modules-option.test.js.snap +++ b/test/__snapshots__/modules-option.test.js.snap @@ -5195,3 +5195,38 @@ exports.locals = { `; exports[`modules composes should supports resolving: warnings 1`] = `Array []`; + +exports[`modules issue #286: errors 1`] = `Array []`; + +exports[`modules issue #286: module (evaluated) 1`] = ` +Array [ + Array [ + 2, + ".a--red { color: red } +", + "", + ], + Array [ + 1, + ".b--main { } +", + "", + ], +] +`; + +exports[`modules issue #286: module 1`] = ` +"exports = module.exports = require(\\"../../../../src/runtime/api.js\\")(false); +// imports +exports.i(require(\\"./dep.css\\"), \\"\\"); + +// module +exports.push([module.id, \\".b--main { }\\\\n\\", \\"\\"]); + +// exports +exports.locals = { + \\"main\\": \\"b--main \\" + require(\\"./dep.css\\").locals[\\"red\\"] + \\"\\" +};" +`; + +exports[`modules issue #286: warnings 1`] = `Array []`; diff --git a/test/errors.test.js b/test/errors.test.js index 41a805e7..09b602f5 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -73,6 +73,7 @@ it('validation', () => { validate({ camelCase: 'unknown' }) ).toThrowErrorMatchingSnapshot(); + expect(() => validate({ importLoaders: false })).not.toThrow(); expect(() => validate({ importLoaders: 0 })).not.toThrow(); expect(() => validate({ importLoaders: 1 })).not.toThrow(); expect(() => validate({ importLoaders: 2 })).not.toThrow(); diff --git a/test/fixtures/modules/issue-286/dep.css b/test/fixtures/modules/issue-286/dep.css new file mode 100644 index 00000000..442fcb11 --- /dev/null +++ b/test/fixtures/modules/issue-286/dep.css @@ -0,0 +1 @@ +.red { color: red } diff --git a/test/fixtures/modules/issue-286/source.css b/test/fixtures/modules/issue-286/source.css new file mode 100644 index 00000000..a0482c69 --- /dev/null +++ b/test/fixtures/modules/issue-286/source.css @@ -0,0 +1 @@ +.main { composes: red from './dep.css'; } diff --git a/test/helpers.js b/test/helpers.js index 831ada63..b555c944 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -40,6 +40,7 @@ function evaluated(output, modules, moduleId = 1) { 'url', 'url/node_modules', 'modules/', + 'modules/issue-286', 'modules/node_modules', 'modules/tests-cases/urls', 'modules/tests-cases/comments', @@ -74,9 +75,6 @@ function evaluated(output, modules, moduleId = 1) { } return 'nothing'; - } else if (modules && module in modules) { - // Compatibility with old tests - return modules[module]; } return `{${module}}`; }); @@ -138,6 +136,7 @@ const moduleConfig = (config) => { : [] ), }, + config.additionalLoader ? config.additionalLoader : {}, { test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/, use: { diff --git a/test/modules-option.test.js b/test/modules-option.test.js index da7348e1..9d094ca0 100644 --- a/test/modules-option.test.js +++ b/test/modules-option.test.js @@ -53,4 +53,37 @@ describe('modules', () => { expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); }); + + it(`issue #286`, async () => { + const config = { + loader: { + test: /source\.css$/, + options: { + importLoaders: false, + modules: true, + localIdentName: 'b--[local]', + }, + }, + additionalLoader: { + test: /dep\.css$/, + loader: path.resolve(__dirname, '../src/index.js'), + options: { + importLoaders: false, + modules: true, + localIdentName: 'a--[local]', + }, + }, + }; + const testId = './modules/issue-286/source.css'; + const stats = await webpack(testId, config); + const { modules } = stats.toJson(); + const module = modules.find((m) => m.id === testId); + + expect(module.source).toMatchSnapshot('module'); + expect(evaluated(module.source, modules)).toMatchSnapshot( + 'module (evaluated)' + ); + expect(stats.compilation.warnings).toMatchSnapshot('warnings'); + expect(stats.compilation.errors).toMatchSnapshot('errors'); + }); });