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

Commit d5a1de2

Browse files
akihikodakimichael-ciniawsky
authored andcommitted
fix: refer to the entrypoint instead of the first module (module.identifier) (#601)
1 parent 5286ab2 commit d5a1de2

File tree

8 files changed

+51
-6
lines changed

8 files changed

+51
-6
lines changed

src/loader.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,16 @@ export function pitch(request) {
9595
}
9696
try {
9797
let text = this.exec(source, request);
98-
if (typeof text === 'string') { text = [[0, text]]; }
99-
text.forEach((item) => {
100-
const id = item[0];
101-
compilation.modules.forEach((module) => {
102-
if (module.id === id) { item[0] = module.identifier(); }
98+
if (typeof text === 'string') {
99+
text = [[compilation.entries[0].identifier(), text]];
100+
} else {
101+
text.forEach((item) => {
102+
const id = item[0];
103+
compilation.modules.forEach((module) => {
104+
if (module.id === id) { item[0] = module.identifier(); }
105+
});
103106
});
104-
});
107+
}
105108
this[NS](text, query);
106109
if (text.locals && typeof resultSource !== 'undefined') {
107110
resultSource += `\nmodule.exports = ${JSON.stringify(text.locals)};`;

test/__snapshots__/webpack-integration.test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,9 @@ exports[`Webpack Integration Tests splitted-chunk 1`] = `
160160
exports[`Webpack Integration Tests splitted-multiple-entries 1`] = `""`;
161161

162162
exports[`Webpack Integration Tests splitted-multiple-entries 2`] = `""`;
163+
164+
exports[`Webpack Integration Tests string-export-with-optimize-module-order 1`] = `
165+
"a
166+
b
167+
"
168+
`;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require("./module")();
2+
module.exports = "a\n";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require("./module")();
2+
module.exports = "b\n";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a
2+
b
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(source) {
2+
return source;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = () => {};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import ExtractTextPlugin from '../../../src/index';
2+
3+
function moduleOrderOptimizer() {
4+
this.plugin("after-plugins", compiler =>
5+
compiler.plugin("compilation", compilation =>
6+
compilation.plugin("optimize-module-order", modules => {
7+
const index = modules.findIndex(module => module.rawRequest == "./module");
8+
[modules[0], modules[index]] = [modules[index], modules[0]];
9+
})));
10+
}
11+
12+
module.exports = {
13+
entry: ['./a', './b'],
14+
module: {
15+
loaders: [
16+
{
17+
test: /(a|b)\.js$/,
18+
use: ExtractTextPlugin.extract('./loader')
19+
},
20+
],
21+
},
22+
plugins: [
23+
moduleOrderOptimizer,
24+
new ExtractTextPlugin('[name].txt'),
25+
],
26+
};

0 commit comments

Comments
 (0)