Skip to content

Commit 3b47d0d

Browse files
refactor: enables icss only when css modules enabled (#1103)
BREAKING CHANGE: `icss` plugin disable by default, you need to setup the `modules` option to enable it
1 parent 76f1480 commit 3b47d0d

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/index.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,28 @@ export default function loader(content, map, meta) {
3535
const sourceMap = options.sourceMap || false;
3636
const plugins = [];
3737

38-
if (shouldUseModulesPlugins(options.modules, this.resourcePath)) {
39-
plugins.push(...getModulesPlugins(options, this));
40-
}
41-
4238
const exportType = options.onlyLocals ? 'locals' : 'full';
4339
const preRequester = getPreRequester(this);
4440
const urlHandler = (url) =>
4541
stringifyRequest(this, preRequester(options.importLoaders) + url);
46-
const icssResolver = this.getResolve({
47-
mainFields: ['css', 'style', 'main', '...'],
48-
mainFiles: ['index', '...'],
49-
});
5042

51-
plugins.push(
52-
icssParser({
53-
context: this.context,
54-
rootContext: this.rootContext,
55-
resolver: icssResolver,
56-
urlHandler,
57-
})
58-
);
43+
if (shouldUseModulesPlugins(options.modules, this.resourcePath)) {
44+
plugins.push(...getModulesPlugins(options, this));
45+
46+
const icssResolver = this.getResolve({
47+
mainFields: ['css', 'style', 'main', '...'],
48+
mainFiles: ['index', '...'],
49+
});
50+
51+
plugins.push(
52+
icssParser({
53+
context: this.context,
54+
rootContext: this.rootContext,
55+
resolver: icssResolver,
56+
urlHandler,
57+
})
58+
);
59+
}
5960

6061
if (options.import !== false && exportType === 'full') {
6162
const resolver = this.getResolve({

test/icss.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ const testCases = fs.readdirSync(testCasesPath);
1616
describe('ICSS', () => {
1717
testCases.forEach((name) => {
1818
it(`show work with the case "${name}"`, async () => {
19-
const compiler = getCompiler(`./icss/tests-cases/${name}/source.js`);
19+
const compiler = getCompiler(`./icss/tests-cases/${name}/source.js`, {
20+
modules: 'global',
21+
});
2022
const stats = await compile(compiler);
2123

2224
expect(

0 commit comments

Comments
 (0)