Skip to content

Commit dd35c6a

Browse files
committed
fix splitChunks support
1 parent 7c6a6e2 commit dd35c6a

File tree

7 files changed

+53
-0
lines changed

7 files changed

+53
-0
lines changed

src/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ class CssModule extends webpack.Module {
5252
return `css ${requestShortener.shorten(this._identifier)}${this._identifierIndex ? ` (${this._identifierIndex})` : ''}`;
5353
}
5454

55+
nameForCondition() {
56+
const resource = this._identifier.split('!').pop();
57+
const idx = resource.indexOf('?');
58+
if (idx >= 0) return resource.substr(0, idx);
59+
return resource;
60+
}
61+
5562
build(options, compilation, resolver, fileSystem, callback) {
5663
this.buildInfo = {};
5764
this.buildMeta = {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
body { background: red; }
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* This could be bootstrap.css */
2+
body {
3+
background: green;
4+
}
5+

test/cases/split-chunks/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import 'bootstrap.css';
2+
import './style.css';

test/cases/split-chunks/node_modules/bootstrap.css

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cases/split-chunks/style.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body { background: red; }
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const Self = require('../../../');
2+
3+
module.exports = {
4+
entry: './index.js',
5+
module: {
6+
rules: [
7+
{
8+
test: /\.css$/,
9+
use: [
10+
Self.loader,
11+
'css-loader',
12+
],
13+
},
14+
],
15+
},
16+
optimization: {
17+
splitChunks: {
18+
chunks: 'all',
19+
cacheGroups: {
20+
vendors: {
21+
test: /node_modules/,
22+
enforce: true
23+
}
24+
}
25+
}
26+
},
27+
plugins: [
28+
new Self({
29+
filename: '[name].css',
30+
}),
31+
],
32+
};

0 commit comments

Comments
 (0)