removed DedupePlugin

it's no longer needed for npm3
and causes many issues
This commit is contained in:
Tobias Koppers 2016-11-10 08:52:00 +01:00
parent ba93f8481b
commit 91cbb4c288
22 changed files with 6 additions and 680 deletions

View File

@ -37,7 +37,6 @@ module.exports = function(optimist) {
.describe("optimize-max-chunks", "Try to keep the chunk count below a limit")
.describe("optimize-min-chunk-size", "Try to keep the chunk size above a limit")
.boolean("optimize-minimize").describe("optimize-minimize", "Minimize javascript and switches loaders to minimizing")
.boolean("optimize-dedupe").describe("optimize-dedupe", "Optimize duplicate module sources in the bundle")
.string("prefetch").describe("prefetch", "Prefetch this request")
.string("provide").describe("provide", "Provide these modules as free vars in all modules")
.boolean("labeled-modules").describe("labeled-modules", "Enables labeled modules")

View File

@ -219,11 +219,6 @@ module.exports = function(yargs) {
describe: "Minimize javascript and switches loaders to minimizing",
group: OPTIMIZE_GROUP
},
"optimize-dedupe": {
type: "boolean",
describe: "Optimize duplicate module sources in the bundle",
group: OPTIMIZE_GROUP
},
"prefetch": {
type: "string",
describe: "Prefetch this request (Example: --prefetch ./file.js)",

View File

@ -457,12 +457,6 @@ module.exports = function(yargs, argv, convertOptions) {
}));
});
ifBooleanArg("optimize-dedupe", function() {
ensureArray(options, "plugins");
var DedupePlugin = require("../lib/optimize/DedupePlugin");
options.plugins.push(new DedupePlugin());
});
ifArg("prefetch", function(request) {
ensureArray(options, "plugins");
var PrefetchPlugin = require("../lib/PrefetchPlugin");

View File

@ -1,319 +0,0 @@
# example.js
``` javascript
var a = require("./a");
var b = require("./b");
a.x !== b.x;
a.y !== b.y;
```
# a/index.js
``` javascript
module.exports = {
x: require("./x"),
y: require("./y"),
z: require("../z")
}
```
# a/x.js
``` javascript
module.exports = {"this is": "x"};
```
# a/y.js
``` javascript
module.exports = {"this is": "y", "but in": "a"};
```
# b/index.js
``` javascript
module.exports = {
x: require("./x"),
y: require("./y"),
z: require("../z")
}
```
# b/x.js
``` javascript
module.exports = {"this is": "x"};
```
# b/y.js
``` javascript
module.exports = {"this is": "y", "but in": "b"};
```
# z.js
``` javascript
module.exports = {"this is": "z"};
```
# js/output.js
<details><summary>`/******/ (function(modules) { /* webpackBootstrap */ })`</summary>
``` javascript
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // identity function for calling harmory imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/ // define getter function for harmory exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ };
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "js/";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 7);
/******/ })
/************************************************************************/
```
</details>
``` javascript
/******/ ((function(modules) {
// Check all modules for deduplicated modules
for(var i in modules) {
if(Object.prototype.hasOwnProperty.call(modules, i)) {
switch(typeof modules[i]) {
case "function": break;
case "object":
// Module can be created from a template
modules[i] = (function(_m) {
var args = _m.slice(1), fn = modules[_m[0]];
return function (a,b,c) {
fn.apply(this, [a,b,c].concat(args));
};
}(modules[i]));
break;
default:
// Module is a copy of another module
modules[i] = modules[modules[i]];
break;
}
}
}
return modules;
}([
/* 0 */
/* unknown exports provided */
/* all exports used */
/*!**************!*\
!*** ./z.js ***!
\**************/
/***/ function(module, exports) {
module.exports = {"this is": "z"};
/***/ },
/* 1 */
/* unknown exports provided */
/* all exports used */
/*!********************!*\
!*** ./a/index.js ***!
\********************/
[8, 3, 4],
/* 2 */
/* unknown exports provided */
/* all exports used */
/*!********************!*\
!*** ./b/index.js ***!
\********************/
[8, 5, 6],
/* 3 */
/* unknown exports provided */
/* all exports used */
/*!****************!*\
!*** ./a/x.js ***!
\****************/
/***/ function(module, exports) {
module.exports = {"this is": "x"};
/***/ },
/* 4 */
/* unknown exports provided */
/* all exports used */
/*!****************!*\
!*** ./a/y.js ***!
\****************/
/***/ function(module, exports) {
module.exports = {"this is": "y", "but in": "a"};
/***/ },
/* 5 */
/* unknown exports provided */
/* all exports used */
/*!****************!*\
!*** ./b/x.js ***!
\****************/
3,
/* 6 */
/* unknown exports provided */
/* all exports used */
/*!****************!*\
!*** ./b/y.js ***!
\****************/
/***/ function(module, exports) {
module.exports = {"this is": "y", "but in": "b"};
/***/ },
/* 7 */
/* unknown exports provided */
/* all exports used */
/*!********************!*\
!*** ./example.js ***!
\********************/
/***/ function(module, exports, __webpack_require__) {
var a = __webpack_require__(/*! ./a */ 1);
var b = __webpack_require__(/*! ./b */ 2);
a.x !== b.x;
a.y !== b.y;
/***/ },
/* 8 */
/*!***********************************!*\
!*** template of 1 referencing 0 ***!
\***********************************/
/***/ function(module, exports, __webpack_require__, __webpack_module_template_argument_0__, __webpack_module_template_argument_1__) {
module.exports = {
x: __webpack_require__(__webpack_module_template_argument_0__),
y: __webpack_require__(__webpack_module_template_argument_1__),
z: __webpack_require__(/*! ../z */ 0)
}
/***/ }
/******/ ])));
```
# Info
## Uncompressed
```
Hash: 4ef665e7da89c97bd89f
Version: webpack 2.1.0-beta.25
Time: 139ms
Asset Size Chunks Chunk Names
output.js 5.05 kB 0 [emitted] main
Entrypoint main = output.js
chunk {0} output.js (main) 513 bytes [entry] [rendered]
> main [7] ./example.js
[0] ./z.js 34 bytes {0} [built]
cjs require ../z [1] ./a/index.js 4:4-19
cjs require ../z [2] ./b/index.js 4:4-19
[1] ./a/index.js 80 bytes {0} [built]
cjs require ./a [7] ./example.js 1:8-22
[2] ./b/index.js 80 bytes {0} [built]
cjs require ./b [7] ./example.js 2:8-22
[3] ./a/x.js 34 bytes {0} [built]
cjs require ./x [1] ./a/index.js 2:4-18
[4] ./a/y.js 49 bytes {0} [built]
cjs require ./y [1] ./a/index.js 3:4-18
[5] ./b/x.js 34 bytes {0} [built]
cjs require ./x [2] ./b/index.js 2:4-18
[6] ./b/y.js 49 bytes {0} [built]
cjs require ./y [2] ./b/index.js 3:4-18
[7] ./example.js 73 bytes {0} [built]
[8] template of 1 referencing 0 80 bytes {0} [not cacheable] [built]
[no exports used]
template 0 [1] ./a/index.js
template 0 [2] ./b/index.js
```
## Minimized (uglify-js, no zip)
```
Hash: 4ef665e7da89c97bd89f
Version: webpack 2.1.0-beta.25
Time: 258ms
Asset Size Chunks Chunk Names
output.js 1.08 kB 0 [emitted] main
Entrypoint main = output.js
chunk {0} output.js (main) 513 bytes [entry] [rendered]
> main [7] ./example.js
[0] ./z.js 34 bytes {0} [built]
cjs require ../z [1] ./a/index.js 4:4-19
cjs require ../z [2] ./b/index.js 4:4-19
[1] ./a/index.js 80 bytes {0} [built]
cjs require ./a [7] ./example.js 1:8-22
[2] ./b/index.js 80 bytes {0} [built]
cjs require ./b [7] ./example.js 2:8-22
[3] ./a/x.js 34 bytes {0} [built]
cjs require ./x [1] ./a/index.js 2:4-18
[4] ./a/y.js 49 bytes {0} [built]
cjs require ./y [1] ./a/index.js 3:4-18
[5] ./b/x.js 34 bytes {0} [built]
cjs require ./x [2] ./b/index.js 2:4-18
[6] ./b/y.js 49 bytes {0} [built]
cjs require ./y [2] ./b/index.js 3:4-18
[7] ./example.js 73 bytes {0} [built]
[8] template of 1 referencing 0 80 bytes {0} [not cacheable] [built]
[no exports used]
template 0 [1] ./a/index.js
template 0 [2] ./b/index.js
```

View File

@ -1,5 +0,0 @@
module.exports = {
x: require("./x"),
y: require("./y"),
z: require("../z")
}

View File

@ -1 +0,0 @@
module.exports = {"this is": "x"};

View File

@ -1 +0,0 @@
module.exports = {"this is": "y", "but in": "a"};

View File

@ -1,5 +0,0 @@
module.exports = {
x: require("./x"),
y: require("./y"),
z: require("../z")
}

View File

@ -1 +0,0 @@
module.exports = {"this is": "x"};

View File

@ -1 +0,0 @@
module.exports = {"this is": "y", "but in": "b"};

View File

@ -1 +0,0 @@
require("../build-common");

View File

@ -1,4 +0,0 @@
var a = require("./a");
var b = require("./b");
a.x !== b.x;
a.y !== b.y;

View File

@ -1,68 +0,0 @@
# example.js
``` javascript
{{example.js}}
```
# a/index.js
``` javascript
{{a/index.js}}
```
# a/x.js
``` javascript
{{a/x.js}}
```
# a/y.js
``` javascript
{{a/y.js}}
```
# b/index.js
``` javascript
{{b/index.js}}
```
# b/x.js
``` javascript
{{b/x.js}}
```
# b/y.js
``` javascript
{{b/y.js}}
```
# z.js
``` javascript
{{z.js}}
```
# js/output.js
``` javascript
{{js/output.js}}
```
# Info
## Uncompressed
```
{{stdout}}
```
## Minimized (uglify-js, no zip)
```
{{min:stdout}}
```

View File

@ -1,6 +0,0 @@
var webpack = require("../../");
module.exports = {
plugins: [
new webpack.optimize.DedupePlugin()
]
}

View File

@ -1 +0,0 @@
module.exports = {"this is": "z"};

View File

@ -2,228 +2,11 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var ConcatSource = require("webpack-sources").ConcatSource;
var TemplateArgumentDependency = require("../dependencies/TemplateArgumentDependency");
function DedupePlugin() {}
module.exports = DedupePlugin;
DedupePlugin.prototype.apply = function(compiler) {
compiler.plugin("compilation", function(compilation) {
compilation.notCacheable = "DedupePlugin";
compilation.dependencyTemplates.set(TemplateArgumentDependency, new TemplateArgumentDependency.Template());
compilation.plugin("after-optimize-tree", function(chunks, modules) {
var modulesByHash = {};
var allDups = [];
modules.forEach(function(module) {
if(!module.getSourceHash || !module.getAllModuleDependencies || !module.createTemplate || !module.getTemplateArguments || module.blocks.length > 0) return;
var hash = module.getSourceHash();
var dupModule = modulesByHash[hash];
if(dupModule) {
if(dupModule.duplicates) {
dupModule.duplicates.push(module);
module.duplicates = dupModule.duplicates;
} else {
allDups.push(module.duplicates = dupModule.duplicates = [dupModule, module]);
}
} else {
modulesByHash[hash] = module;
}
});
var entryChunks = chunks.filter(function(c) {
return c.hasRuntime();
});
entryChunks.forEach(function(chunk) { // for each entry chunk
var hasDeduplicatedModules = false;
(function x(dups, roots, visited, chunk) {
var currentDups = [];
var currentRoots = [];
chunk.modules.forEach(function(module) {
if(module.duplicates) {
if(!module.rootDuplicatesChunks)
module.rootDuplicatesChunks = module.chunks.slice();
var chunkIndex = module.rootDuplicatesChunks.indexOf(chunk);
if(!module.rootDuplicates) module.rootDuplicates = [];
var idx = currentDups.indexOf(module.duplicates);
if(idx >= 0) {
module.rootDuplicates[chunkIndex] = currentRoots[idx];
module.rootDuplicates[chunkIndex].push(module);
module.rootDuplicates[chunkIndex].commonModules =
mergeCommonModules(module.rootDuplicates[chunkIndex].commonModules, module.getAllModuleDependencies());
hasDeduplicatedModules = true;
} else {
idx = dups.indexOf(module.duplicates);
if(idx < 0) {
module.rootDuplicates[chunkIndex] = [module];
module.rootDuplicates[chunkIndex].commonModules = module.getAllModuleDependencies();
module.rootDuplicates[chunkIndex].initialCommonModulesLength = module.rootDuplicates[chunkIndex].commonModules.length;
dups = dups.concat([module.duplicates]);
roots = roots.concat([module.rootDuplicates[chunkIndex]]);
currentDups = currentDups.concat([module.duplicates]);
currentRoots = currentRoots.concat([module.rootDuplicates[chunkIndex]]);
} else {
module.rootDuplicates[chunkIndex] = roots[idx];
module.rootDuplicates[chunkIndex].commonModules =
mergeCommonModules(module.rootDuplicates[chunkIndex].commonModules, module.getAllModuleDependencies());
hasDeduplicatedModules = true;
}
}
}
});
chunk.chunks.forEach(function(chunk) {
if(visited.indexOf(chunk) < 0)
x(dups, roots, visited.concat(chunk), chunk);
});
currentRoots.forEach(function(roots) {
var commonModules = roots.commonModules;
var initialLength = roots.initialCommonModulesLength;
if(initialLength !== commonModules.length) {
var template = roots[0].createTemplate(commonModules, roots.slice());
roots.template = template;
chunk.addModule(template);
template.addChunk(chunk);
compilation.modules.push(template);
hasDeduplicatedModules = true;
}
});
}([], [], [], chunk));
if(hasDeduplicatedModules)
chunk.__DedupePluginHasDeduplicatedModules = true;
});
});
function mergeCommonModules(commonModules, newModules) {
return commonModules.filter(function(module) {
return newModules.indexOf(module) >= 0;
});
}
compilation.moduleTemplate.plugin("package", function(moduleSource, module, chunk) {
if(!module.rootDuplicatesChunks || !chunk) return moduleSource;
var chunkIndex = module.rootDuplicatesChunks.indexOf(chunk);
if(!module.rootDuplicates || !module.rootDuplicates[chunkIndex]) return moduleSource;
var rootDuplicates = module.rootDuplicates[chunkIndex];
var source;
if(rootDuplicates.template) {
rootDuplicates.template.addReason(module, {
type: "template",
request: module.request,
templateModules: rootDuplicates.template.templateModules
});
rootDuplicates.template.reasons.sort(function(a, b) {
if(a.request === b.request) return 0;
return a.request < b.request ? -1 : 1;
});
var array = [JSON.stringify(rootDuplicates.template.id)].concat(module.getTemplateArguments(rootDuplicates.template.templateModules).map(function(module) {
if(module.id === null || module.id === undefined)
return "(function webpackMissingModule() { throw new Error(" + JSON.stringify("Cannot find module") + "); }())";
return JSON.stringify(module.id);
}));
source = new ConcatSource("[" + array.join(", ") + "]");
return source;
} else {
rootDuplicates.sort(function(a, b) {
return a.id - b.id;
});
if(module === rootDuplicates[0]) return moduleSource;
source = new ConcatSource("" + JSON.stringify(rootDuplicates[0].id));
return source;
}
});
compilation.plugin("chunk-hash", function(chunk, hash) {
if(chunk.__DedupePluginHasDeduplicatedModules)
hash.update("DedupePlugin (deduplication code)");
});
compilation.mainTemplate.plugin("add-module", function(source, chunk, hash, varModuleId, varModule) {
// we don't need to test all nested chunks, because `__DedupePluginHasDeduplicatedModules`
// is not set on entry chunks
if(!chunk.__DedupePluginHasDeduplicatedModules) {
return source;
}
return this.asString([
"var _m = " + varModule + ";",
"",
"// Check if module is deduplicated",
"switch(typeof _m) {",
"case \"object\":",
this.indent([
"// Module can be created from a template",
"modules[" + varModuleId + "] = (function(_m) {",
this.indent([
"var args = _m.slice(1), templateId = _m[0];",
"return function (a,b,c) {",
this.indent([
"modules[templateId].apply(this, [a,b,c].concat(args));"
]),
"};"
]),
"}(_m));",
"break;"
]),
"case \"function\":",
this.indent([
"// Normal module",
"modules[" + varModuleId + "] = _m;",
"break;"
]),
"default:",
this.indent([
"// Module is a copy of another module",
"modules[" + varModuleId + "] = modules[_m];",
"break;"
]),
"}"
]);
});
compilation.mainTemplate.plugin("modules", function(orginalSource, chunk) {
if(!chunk.__DedupePluginHasDeduplicatedModules) {
return orginalSource;
}
var source = new ConcatSource();
source.add("(function(modules) {\n");
source.add(this.indent([
"// Check all modules for deduplicated modules",
"for(var i in modules) {",
this.indent([
"if(Object.prototype.hasOwnProperty.call(modules, i)) {",
this.indent([
"switch(typeof modules[i]) {",
"case \"function\": break;",
"case \"object\":",
this.indent([
"// Module can be created from a template",
"modules[i] = (function(_m) {",
this.indent([
"var args = _m.slice(1), fn = modules[_m[0]];",
"return function (a,b,c) {",
this.indent([
"fn.apply(this, [a,b,c].concat(args));"
]),
"};"
]),
"}(modules[i]));",
"break;"
]),
"default:",
this.indent([
"// Module is a copy of another module",
"modules[i] = modules[modules[i]];",
"break;"
]),
"}"
]),
"}"
]),
"}",
"return modules;"
]));
source.add("\n}(");
source.add(orginalSource);
source.add("))");
return source;
});
compilation.warnings.push(new Error("DedupePlugin: This plugin was removed from webpack. remove it from configuration."));
});
};

View File

@ -73,30 +73,17 @@ describe("TestCases", function() {
]
}, {
name: "minimized-source-map",
devtool: "eval-cheap-module-source-map",
minimize: true,
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
}, {
name: "deduped",
plugins: [
new webpack.optimize.DedupePlugin(),
new webpack.NamedModulesPlugin()
]
}, {
name: "minimized-deduped",
name: "minimized-hashed-modules",
minimize: true,
plugins: [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
]
}, {
name: "optimized",
minimize: true,
plugins: [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin()
new webpack.optimize.UglifyJsPlugin(),
new webpack.HashedModuleIdsPlugin()
]
}, {
name: "all-combined",
@ -104,8 +91,6 @@ describe("TestCases", function() {
minimize: true,
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin(),
new webpack.NamedModulesPlugin()
]
@ -113,7 +98,7 @@ describe("TestCases", function() {
describe(config.name, function() {
categories.forEach(function(category) {
describe(category.name, function() {
this.timeout(20000);
this.timeout(30000);
category.tests.filter(function(test) {
var testDirectory = path.join(casesPath, category.name, test);
var filterPath = path.join(testDirectory, "test.filter.js");

View File

@ -39,7 +39,6 @@ app.configure(function() {
plugins: [
new webpack.dependencies.LabeledModulesPlugin(),
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.HotModuleReplacementPlugin()
]
}), {

View File

@ -1 +0,0 @@
module.exports = {ok: 1};

View File

@ -1 +0,0 @@
module.exports = {ok: 1};

View File

@ -1,8 +0,0 @@
it("should allow to dedupe only in a chunk", function (done) {
require(["./a/dedupe", "./b/dedupe"], function(a, b) {
a.should.be.eql({ok: 1});
b.should.be.eql({ok: 1});
a.should.be.not.equal(b);
done();
})
});

View File

@ -1,6 +0,0 @@
var DedupePlugin = require("../../../../lib/optimize/DedupePlugin");
module.exports = {
plugins: [
new DedupePlugin(),
]
};