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

fix: refer to the entrypoint instead of the first module (module.identifier) #601

Merged
merged 1 commit into from Oct 21, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/loader.js
Expand Up @@ -95,13 +95,16 @@ export function pitch(request) {
}
try {
let text = this.exec(source, request);
if (typeof text === 'string') { text = [[0, text]]; }
text.forEach((item) => {
const id = item[0];
compilation.modules.forEach((module) => {
if (module.id === id) { item[0] = module.identifier(); }
if (typeof text === 'string') {
text = [[compilation.entries[0].identifier(), text]];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use [[entries[0].identifier(), text]] too i guess.

} else {
text.forEach((item) => {
const id = item[0];
compilation.modules.forEach((module) => {
if (module.id === id) { item[0] = module.identifier(); }
});
});
});
}
this[NS](text, query);
if (text.locals && typeof resultSource !== 'undefined') {
resultSource += `\nmodule.exports = ${JSON.stringify(text.locals)};`;
Expand Down
6 changes: 6 additions & 0 deletions test/__snapshots__/webpack-integration.test.js.snap
Expand Up @@ -160,3 +160,9 @@ exports[`Webpack Integration Tests splitted-chunk 1`] = `
exports[`Webpack Integration Tests splitted-multiple-entries 1`] = `""`;

exports[`Webpack Integration Tests splitted-multiple-entries 2`] = `""`;

exports[`Webpack Integration Tests string-export-with-optimize-module-order 1`] = `
"a
b
"
`;
2 changes: 2 additions & 0 deletions test/cases/string-export-with-optimize-module-order/a.js
@@ -0,0 +1,2 @@
require("./module")();
module.exports = "a\n";
2 changes: 2 additions & 0 deletions test/cases/string-export-with-optimize-module-order/b.js
@@ -0,0 +1,2 @@
require("./module")();
module.exports = "b\n";
@@ -0,0 +1,2 @@
a
b
3 changes: 3 additions & 0 deletions test/cases/string-export-with-optimize-module-order/loader.js
@@ -0,0 +1,3 @@
module.exports = function(source) {
return source;
}
@@ -0,0 +1 @@
module.exports = () => {};
@@ -0,0 +1,26 @@
import ExtractTextPlugin from '../../../src/index';

function moduleOrderOptimizer() {
this.plugin("after-plugins", compiler =>
compiler.plugin("compilation", compilation =>
compilation.plugin("optimize-module-order", modules => {
const index = modules.findIndex(module => module.rawRequest == "./module");
[modules[0], modules[index]] = [modules[index], modules[0]];
})));
}

module.exports = {
entry: ['./a', './b'],
module: {
loaders: [
{
test: /(a|b)\.js$/,
use: ExtractTextPlugin.extract('./loader')
},
],
},
plugins: [
moduleOrderOptimizer,
new ExtractTextPlugin('[name].txt'),
],
};