Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class MiniCssExtractPlugin {
result.push({
render: () =>
this.renderContentAsset(
chunk,
renderedModules,
compilation.runtimeTemplate.requestShortener
),
Expand All @@ -191,6 +192,7 @@ class MiniCssExtractPlugin {
result.push({
render: () =>
this.renderContentAsset(
chunk,
renderedModules,
compilation.runtimeTemplate.requestShortener
),
Expand Down Expand Up @@ -379,8 +381,24 @@ class MiniCssExtractPlugin {
return obj;
}

renderContentAsset(modules, requestShortener) {
modules.sort((a, b) => a.index2 - b.index2);
renderContentAsset(chunk, modules, requestShortener) {
// get first chunk group and take ordr from this one
// When a chunk is shared between multiple chunk groups
// with different order this can lead to wrong order
// but it's not possible to create a correct order in
// this case. Don't share chunks if you don't like it.
const [chunkGroup] = chunk.groupsIterable;
if (typeof chunkGroup.getModuleIndex2 === 'function') {
modules.sort(
(a, b) => chunkGroup.getModuleIndex2(a) - chunkGroup.getModuleIndex2(b)
);
} else {
// fallback for older webpack versions
// (to avoid a breaking change)
// TODO remove this in next mayor version
// and increase minimum webpack version to 4.12.0
modules.sort((a, b) => a.index2 - b.index2);
}
const source = new ConcatSource();
const externalsSource = new ConcatSource();
for (const m of modules) {
Expand Down
1 change: 1 addition & 0 deletions test/cases/multiple-entry/a.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body { background: red; }
2 changes: 2 additions & 0 deletions test/cases/multiple-entry/async-one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './c.css';
import './d.css';
2 changes: 2 additions & 0 deletions test/cases/multiple-entry/async-two.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './d.css';
import './c.css';
1 change: 1 addition & 0 deletions test/cases/multiple-entry/b.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body { background: green; }
1 change: 1 addition & 0 deletions test/cases/multiple-entry/c.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body { background: blue; }
1 change: 1 addition & 0 deletions test/cases/multiple-entry/d.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body { background: yellow; }
4 changes: 4 additions & 0 deletions test/cases/multiple-entry/expected/async-one.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body { background: blue; }

body { background: yellow; }

4 changes: 4 additions & 0 deletions test/cases/multiple-entry/expected/async-two.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body { background: yellow; }

body { background: blue; }

4 changes: 4 additions & 0 deletions test/cases/multiple-entry/expected/main-one.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body { background: red; }

body { background: green; }

4 changes: 4 additions & 0 deletions test/cases/multiple-entry/expected/main-two.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body { background: green; }

body { background: red; }

3 changes: 3 additions & 0 deletions test/cases/multiple-entry/index-one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './a.css';
import './b.css';
import(/* webpackChunkName: 'async-one' */'./async-one');
3 changes: 3 additions & 0 deletions test/cases/multiple-entry/index-two.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import(/* webpackChunkName: 'async-two' */'./async-two');
import './b.css';
import './a.css';
24 changes: 24 additions & 0 deletions test/cases/multiple-entry/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const Self = require('../../../');

module.exports = {
entry: {
'main-one': './index-one.js',
'main-two': './index-two.js',
},
module: {
rules: [
{
test: /\.css$/,
use: [
Self.loader,
'css-loader',
],
},
],
},
plugins: [
new Self({
filename: '[name].css',
}),
],
};