Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix: Module sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwiens committed Jul 7, 2017
1 parent 28363ab commit 27e3a28
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Expand Up @@ -27,9 +27,10 @@
"presets": [
"env"
],
"sourceMap" : "inline",
"plugins": [
"transform-object-rest-spread"
]
}
}
}
}
3 changes: 1 addition & 2 deletions src/index.js
Expand Up @@ -144,7 +144,6 @@ class ExtractTextPlugin {
async.forEach(chunks, (chunk, callback) => { // eslint-disable-line no-shadow
const extractedChunk = extractedChunks[chunks.indexOf(chunk)];
const shouldExtract = !!(options.allChunks || isInitialOrHasNoParents(chunk));
chunk.sortModules();
async.forEach(chunk.mapModules(c => c), (module, callback) => { // eslint-disable-line no-shadow
let meta = module[NS];
if (meta && (!meta.options.id || meta.options.id === id)) {
Expand Down Expand Up @@ -194,7 +193,7 @@ class ExtractTextPlugin {
compilation.plugin('additional-assets', (callback) => {
extractedChunks.forEach((extractedChunk) => {
if (extractedChunk.getNumberOfModules()) {
extractedChunk.modules.sort((a, b) => {
extractedChunk.sortModules((a, b) => {
if (!options.ignoreOrder && isInvalidOrder(a, b)) {
compilation.errors.push(new OrderUndefinedError(a.getOriginalModule()));
compilation.errors.push(new OrderUndefinedError(b.getOriginalModule()));
Expand Down
10 changes: 10 additions & 0 deletions test/__snapshots__/webpack-integration.test.js.snap
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Webpack Integration Tests chunk-modules-css-wrong-order 1`] = `
".block {
font-size: 16px;
}
.App {
text-align: center;
}
"
`;

exports[`Webpack Integration Tests chunk-modules-nested-ordered-by-id 1`] = `
"body {
margin: 0;
Expand Down
3 changes: 3 additions & 0 deletions test/cases/chunk-modules-css-wrong-order/a.css
@@ -0,0 +1,3 @@
.App {
text-align: center;
}
2 changes: 2 additions & 0 deletions test/cases/chunk-modules-css-wrong-order/a.js
@@ -0,0 +1,2 @@
require('./b.js');
require('./a.css');
3 changes: 3 additions & 0 deletions test/cases/chunk-modules-css-wrong-order/b.css
@@ -0,0 +1,3 @@
.block {
font-size: 16px;
}
1 change: 1 addition & 0 deletions test/cases/chunk-modules-css-wrong-order/b.js
@@ -0,0 +1 @@
require('./b.css');
6 changes: 6 additions & 0 deletions test/cases/chunk-modules-css-wrong-order/expected/file.css
@@ -0,0 +1,6 @@
.block {
font-size: 16px;
}
.App {
text-align: center;
}
1 change: 1 addition & 0 deletions test/cases/chunk-modules-css-wrong-order/index.js
@@ -0,0 +1 @@
require('./a.js');
19 changes: 19 additions & 0 deletions test/cases/chunk-modules-css-wrong-order/webpack.config.js
@@ -0,0 +1,19 @@
import ExtractTextPlugin from '../../../src/index';

module.exports = {
entry: './index',
module: {
loaders: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: { loader: 'style-loader' },
use: { loader: 'css-loader', },
})
},
],
},
plugins: [
new ExtractTextPlugin('file.css'),
],
};

0 comments on commit 27e3a28

Please sign in to comment.