| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,6 +53,8 @@ module.exports = function(optimist) { | |||
| 53 | 53 | ||
| 54 | 54 | .boolean("optimize-minimize").describe("optimize-minimize") | |
| 55 | 55 | ||
| 56 | + .boolean("optimize-occurence-order").describe("optimize-occurence-order") | ||
| 57 | + | ||
| 56 | 58 | .string("provide").describe("provide") | |
| 57 | 59 | ||
| 58 | 60 | .string("plugin").describe("plugin") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ module.exports = function(optimist, argv, convertOptions) { | |||
| 15 | 15 | } | |
| 16 | 16 | if(argv.p) { | |
| 17 | 17 | argv["optimize-minimize"] = true; | |
| 18 | + argv["optimize-occurence-order"] = true; | ||
| 18 | 19 | } | |
| 19 | 20 | ||
| 20 | 21 | function ifArg(name, fn, init) { | |
@@ -249,6 +250,11 @@ module.exports = function(optimist, argv, convertOptions) { | |||
| 249 | 250 | options.optimize.minimize = true; | |
| 250 | 251 | }); | |
| 251 | 252 | ||
| 253 | + ifBooleanArg("optimize-occurence-order", function() { | ||
| 254 | + ensureObject(options, "optimize"); | ||
| 255 | + options.optimize.occurenceOrder = true; | ||
| 256 | + }); | ||
| 257 | + | ||
| 252 | 258 | ifArg("provide", function(value) { | |
| 253 | 259 | ensureObject(options, "provide"); | |
| 254 | 260 | var idx = value.indexOf("="); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,11 +4,13 @@ | |||
| 4 | 4 | */ | |
| 5 | 5 | function Chunk(name) { | |
| 6 | 6 | this.id = null; | |
| 7 | + this.ids = null; | ||
| 7 | 8 | this.name = name; | |
| 8 | 9 | this.modules = []; | |
| 9 | 10 | this.chunks = []; | |
| 10 | 11 | this.parents = []; | |
| 11 | 12 | this.blocks = []; | |
| 13 | + this.rendered = false; | ||
| 12 | 14 | } | |
| 13 | 15 | module.exports = Chunk; | |
| 14 | 16 | ||
@@ -127,7 +129,9 @@ Chunk.prototype.isEmpty = function() { | |||
| 127 | 129 | }; | |
| 128 | 130 | ||
| 129 | 131 | Chunk.prototype.updateHash = function(hash) { | |
| 130 | - hash.update(this.id + ""); | ||
| 132 | + hash.update(this.id + " "); | ||
| 133 | + hash.update(this.ids ? this.ids.join(",") : ""); | ||
| 134 | + hash.update(this.name + ""); | ||
| 131 | 135 | this.modules.forEach(function(m) { | |
| 132 | 136 | m.updateHash(hash); | |
| 133 | 137 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ ChunkTemplate.prototype.render = function(chunk, moduleTemplate, dependencyTempl | |||
| 22 | 22 | }); | |
| 23 | 23 | source.add("\n\n"); | |
| 24 | 24 | source.add(this.asString(this.renderFooter(chunk))); | |
| 25 | + chunk.rendered = true; | ||
| 25 | 26 | return source; | |
| 26 | 27 | }; | |
| 27 | 28 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,9 +46,9 @@ Compilation.prototype = Object.create(Tapable.prototype); | |||
| 46 | 46 | Compilation.prototype.addModule = function(module) { | |
| 47 | 47 | var identifier = module.identifier(); | |
| 48 | 48 | if(this._modules[identifier]) return false; | |
| 49 | - if(this.cache && this.cache[identifier]) { | ||
| 50 | - var cacheModule = this.cache[identifier]; | ||
| 51 | - | ||
| 49 | + if(this.cache && this.cache["m" + identifier]) { | ||
| 50 | + var cacheModule = this.cache["m" + identifier]; | ||
| 51 | + | ||
| 52 | 52 | var rebuild = true; | |
| 53 | 53 | if(!cacheModule.error && cacheModule.cacheable && this.fileTimestamps && this.contextTimestamps) { | |
| 54 | 54 | rebuild = cacheModule.needRebuild(this.fileTimestamps, this.contextTimestamps); | |
@@ -65,10 +65,12 @@ Compilation.prototype.addModule = function(module) { | |||
| 65 | 65 | this.warnings.push(err); | |
| 66 | 66 | }, this); | |
| 67 | 67 | return cacheModule; | |
| 68 | + } else { | ||
| 69 | + module.lastId = cacheModule.id; | ||
| 68 | 70 | } | |
| 69 | 71 | } | |
| 70 | 72 | this._modules[identifier] = module; | |
| 71 | - if(this.cache) this.cache[identifier] = module; | ||
| 73 | + if(this.cache) this.cache["m" + identifier] = module; | ||
| 72 | 74 | this.modules.push(module); | |
| 73 | 75 | return true; | |
| 74 | 76 | }; | |
@@ -164,7 +166,7 @@ Compilation.prototype.processModuleDependencies = function(module, callback) { | |||
| 164 | 166 | } | |
| 165 | 167 | if(err) return errorOrWarningAndCallback(new ModuleNotFoundError(module, err)); | |
| 166 | 168 | if(!dependantModule) return callback(); | |
| 167 | - | ||
| 169 | + | ||
| 168 | 170 | var newModule = this.addModule(dependantModule); | |
| 169 | 171 | ||
| 170 | 172 | if(!newModule) { | |
@@ -180,15 +182,15 @@ Compilation.prototype.processModuleDependencies = function(module, callback) { | |||
| 180 | 182 | ||
| 181 | 183 | if(newModule instanceof Module) { // from cache | |
| 182 | 184 | dependantModule = newModule; | |
| 183 | - | ||
| 185 | + | ||
| 184 | 186 | dependencies.forEach(function(dep) { | |
| 185 | 187 | dep.module = dependantModule; | |
| 186 | 188 | dependantModule.addReason(module, dep); | |
| 187 | 189 | }); | |
| 188 | 190 | ||
| 189 | 191 | return this.processModuleDependencies(dependantModule, callback); | |
| 190 | 192 | } | |
| 191 | - | ||
| 193 | + | ||
| 192 | 194 | this.buildModule(dependantModule, function(err) { | |
| 193 | 195 | if(err) return errorOrWarningAndCallback(err); | |
| 194 | 196 | ||
@@ -231,7 +233,7 @@ Compilation.prototype.addEntry = function process(context, entry, name, callback | |||
| 231 | 233 | if(!result) { | |
| 232 | 234 | return callback(new Error("Entry module is already added")); | |
| 233 | 235 | } | |
| 234 | - | ||
| 236 | + | ||
| 235 | 237 | if(result instanceof Module) { | |
| 236 | 238 | module = result; | |
| 237 | 239 | } | |
@@ -248,7 +250,7 @@ Compilation.prototype.addEntry = function process(context, entry, name, callback | |||
| 248 | 250 | entryReady.call(this); | |
| 249 | 251 | }.bind(this)); | |
| 250 | 252 | } | |
| 251 | - | ||
| 253 | + | ||
| 252 | 254 | function entryReady() { | |
| 253 | 255 | this.processModuleDependencies(module, function(err) { | |
| 254 | 256 | if(err) return callback(err); | |
@@ -272,7 +274,9 @@ Compilation.prototype.seal = function seal(callback) { | |||
| 272 | 274 | this.applyPlugins("after-optimize-modules", this.modules); | |
| 273 | 275 | this.applyPlugins("optimize-chunks", this.chunks); | |
| 274 | 276 | this.applyPlugins("after-optimize-chunks", this.chunks); | |
| 277 | + this.applyPlugins("optimize-module-order", this.modules); | ||
| 275 | 278 | this.applyModuleIds(); | |
| 279 | + this.applyPlugins("optimize-chunk-order", this.chunks); | ||
| 276 | 280 | this.applyChunkIds(); | |
| 277 | 281 | this.applyPlugins("optimize-module-ids", this.modules); | |
| 278 | 282 | this.applyPlugins("after-optimize-module-ids", this.modules); | |
@@ -337,77 +341,25 @@ Compilation.prototype.processDependenciesBlockForChunk = function processDepende | |||
| 337 | 341 | }; | |
| 338 | 342 | ||
| 339 | 343 | Compilation.prototype.applyModuleIds = function applyModuleIds() { | |
| 340 | - var i = 0; | ||
| 341 | - function entryChunks(m) { | ||
| 342 | - return m.chunks.filter(function(c) { | ||
| 343 | - return c.entry; | ||
| 344 | - }).length; | ||
| 345 | - } | ||
| 346 | - function occursInEntry(m) { | ||
| 347 | - return m.reasons.map(function(r) { | ||
| 348 | - if(!r.module) return 0; | ||
| 349 | - return entryChunks(r.module); | ||
| 350 | - }).reduce(function(a, b) { return a+b; }, 0) + entryChunks(m); | ||
| 351 | - } | ||
| 352 | - function occurs(m) { | ||
| 353 | - return m.reasons.map(function(r) { | ||
| 354 | - if(!r.module) return 0; | ||
| 355 | - return r.module.chunks.length; | ||
| 356 | - }).reduce(function(a, b) { return a+b; }, 0) + m.chunks.length; | ||
| 357 | - } | ||
| 358 | - this.modules.sort(function(a, b) { | ||
| 359 | - var aEntryOccurs = occursInEntry(a); | ||
| 360 | - var bEntryOccurs = occursInEntry(b); | ||
| 361 | - if(aEntryOccurs > bEntryOccurs) return -1; | ||
| 362 | - if(aEntryOccurs < bEntryOccurs) return 1; | ||
| 363 | - var aOccurs = occurs(a); | ||
| 364 | - var bOccurs = occurs(b); | ||
| 365 | - if(aOccurs > bOccurs) return -1; | ||
| 366 | - if(aOccurs < bOccurs) return 1; | ||
| 367 | - if(a.identifier() > b.identifier()) return 1; | ||
| 368 | - if(a.identifier() < b.identifier()) return -1; | ||
| 369 | - return 0; | ||
| 370 | - }); | ||
| 344 | + var i = this.cache && this.cache["nextModuleId"] || 1; | ||
| 345 | + var usedIds = {0:true}; | ||
| 371 | 346 | this.modules.forEach(function(module) { | |
| 372 | - if(module.id === null) | ||
| 373 | - module.id = ++i; | ||
| 347 | + if(module.id === null) { | ||
| 348 | + if(module.lastId > 0) { | ||
| 349 | + if(!usedIds[module.lastId]) { | ||
| 350 | + usedIds[module.lastId] = true; | ||
| 351 | + module.id = module.lastId; | ||
| 352 | + return; | ||
| 353 | + } | ||
| 354 | + } | ||
| 355 | + module.id = i++; | ||
| 356 | + } | ||
| 374 | 357 | }); | |
| 358 | + if(this.cache) this.cache["nextModuleId"] = i; | ||
| 375 | 359 | }; | |
| 376 | 360 | ||
| 377 | 361 | Compilation.prototype.applyChunkIds = function applyChunkIds() { | |
| 378 | 362 | var i = 0; | |
| 379 | - function occursInEntry(c) { | ||
| 380 | - return c.parents.filter(function(p) { | ||
| 381 | - return p.entry; | ||
| 382 | - }).length; | ||
| 383 | - } | ||
| 384 | - function occurs(c) { | ||
| 385 | - return c.blocks.length; | ||
| 386 | - } | ||
| 387 | - this.chunks.forEach(function(c) { | ||
| 388 | - c.modules.sort(function(a, b) { | ||
| 389 | - if(a.identifier() > b.identifier()) return 1; | ||
| 390 | - if(a.identifier() < b.identifier()) return -1; | ||
| 391 | - return 0; | ||
| 392 | - }); | ||
| 393 | - }); | ||
| 394 | - this.chunks.sort(function(a, b) { | ||
| 395 | - var aEntryOccurs = occursInEntry(a); | ||
| 396 | - var bEntryOccurs = occursInEntry(b); | ||
| 397 | - if(aEntryOccurs > bEntryOccurs) return -1; | ||
| 398 | - if(aEntryOccurs < bEntryOccurs) return 1; | ||
| 399 | - var aOccurs = occurs(a); | ||
| 400 | - var bOccurs = occurs(b); | ||
| 401 | - if(aOccurs > bOccurs) return -1; | ||
| 402 | - if(aOccurs < bOccurs) return 1; | ||
| 403 | - if(a.modules.length > b.modules.length) return -1; | ||
| 404 | - if(a.modules.length < b.modules.length) return 1; | ||
| 405 | - for(var i = 0; i < a.modules.length; i++) { | ||
| 406 | - if(a.modules[i].identifier() > b.modules[i].identifier()) return -1; | ||
| 407 | - if(a.modules[i].identifier() < b.modules[i].identifier()) return 1; | ||
| 408 | - } | ||
| 409 | - return 0; | ||
| 410 | - }); | ||
| 411 | 363 | this.chunks.forEach(function(chunk) { | |
| 412 | 364 | if(chunk.id === null) | |
| 413 | 365 | chunk.id = ++i; | |
@@ -494,7 +446,17 @@ Compilation.prototype.createChunkAssets = function createChunkAssets() { | |||
| 494 | 446 | var source; | |
| 495 | 447 | var file; | |
| 496 | 448 | if(chunk.entry) { | |
| 497 | - source = this.mainTemplate.render(hash, chunk, this.moduleTemplate, this.dependencyTemplates); | ||
| 449 | + if(this.cache && this.cache["c" + chunk.id + chunk.name] && this.cache["c" + chunk.id + chunk.name].hash == hash) { | ||
| 450 | + source = this.cache["c" + chunk.id + chunk.name].source; | ||
| 451 | + } else { | ||
| 452 | + source = this.mainTemplate.render(hash, chunk, this.moduleTemplate, this.dependencyTemplates); | ||
| 453 | + if(this.cache) { | ||
| 454 | + this.cache["c" + chunk.id + chunk.name] = { | ||
| 455 | + hash: hash, | ||
| 456 | + source: source | ||
| 457 | + } | ||
| 458 | + } | ||
| 459 | + } | ||
| 498 | 460 | this.assets[ | |
| 499 | 461 | file = filename | |
| 500 | 462 | .replace(Template.REGEXP_HASH, hash) | |
@@ -504,7 +466,23 @@ Compilation.prototype.createChunkAssets = function createChunkAssets() { | |||
| 504 | 466 | chunk.files.push(file); | |
| 505 | 467 | this.applyPlugins("chunk-asset", chunk, file); | |
| 506 | 468 | } else { | |
| 507 | - source = this.chunkTemplate.render(chunk, this.moduleTemplate, this.dependencyTemplates); | ||
| 469 | + if(this.cache) { | ||
| 470 | + var chunkHash = new (require("crypto").Hash)("md5"); | ||
| 471 | + chunk.updateHash(chunkHash); | ||
| 472 | + this.chunkTemplate.updateHash(chunkHash); | ||
| 473 | + chunkHash = chunkHash.digest("hex"); | ||
| 474 | + } | ||
| 475 | + if(this.cache && this.cache["c" + chunk.id] && this.cache["c" + chunk.id].hash == chunkHash) { | ||
| 476 | + source = this.cache["c" + chunk.id].source; | ||
| 477 | + } else { | ||
| 478 | + source = this.chunkTemplate.render(chunk, this.moduleTemplate, this.dependencyTemplates); | ||
| 479 | + if(this.cache) { | ||
| 480 | + this.cache["c" + chunk.id] = { | ||
| 481 | + hash: chunkHash, | ||
| 482 | + source: source | ||
| 483 | + } | ||
| 484 | + } | ||
| 485 | + } | ||
| 508 | 486 | this.assets[ | |
| 509 | 487 | file = chunkFilename | |
| 510 | 488 | .replace(Template.REGEXP_HASH, hash) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,7 +100,7 @@ function Compiler() { | |||
| 100 | 100 | this.outputFileSystem = null; | |
| 101 | 101 | this.inputFileSystem = null; | |
| 102 | 102 | this.separateExecutor = null; | |
| 103 | - | ||
| 103 | + | ||
| 104 | 104 | this.fileTimestamps = {}; | |
| 105 | 105 | this.contextTimestamps = {}; | |
| 106 | 106 | ||
@@ -179,10 +179,18 @@ Compiler.prototype.emitAssets = function(compilation, callback) { | |||
| 179 | 179 | } else writeOut.call(this); | |
| 180 | 180 | function writeOut(err) { | |
| 181 | 181 | if(err) return callback(err); | |
| 182 | - var content = compilation.assets[file].source(); | ||
| 182 | + var targetPath = this.outputFileSystem.join(this.outputPath, file); | ||
| 183 | + var source = compilation.assets[file]; | ||
| 184 | + if(source.existsAt === targetPath) { | ||
| 185 | + source.emitted = false; | ||
| 186 | + return callback(); | ||
| 187 | + } | ||
| 188 | + var content = source.source(); | ||
| 183 | 189 | if(!Buffer.isBuffer(content)) | |
| 184 | 190 | content = new Buffer(content, "utf-8"); | |
| 185 | - this.outputFileSystem.writeFile(this.outputFileSystem.join(this.outputPath, file), content, callback); | ||
| 191 | + source.existsAt = targetPath; | ||
| 192 | + source.emitted = true; | ||
| 193 | + this.outputFileSystem.writeFile(targetPath, content, callback); | ||
| 186 | 194 | }; | |
| 187 | 195 | ||
| 188 | 196 | }.bind(this), function(err) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,6 +42,7 @@ MainTemplate.prototype.render = function(hash, chunk, moduleTemplate, dependency | |||
| 42 | 42 | source.add(moduleTemplate.render(module, dependencyTemplates)); | |
| 43 | 43 | }); | |
| 44 | 44 | source.add("\n/******/ })"); | |
| 45 | + chunk.rendered = true; | ||
| 45 | 46 | return source; | |
| 46 | 47 | }; | |
| 47 | 48 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ function Module() { | |||
| 11 | 11 | this.context = null; | |
| 12 | 12 | this.reasons = []; | |
| 13 | 13 | this.debugId = debugId++; | |
| 14 | + this.lastId = -1; | ||
| 14 | 15 | this.id = null; | |
| 15 | 16 | this.chunks = []; | |
| 16 | 17 | this.warnings = []; | |
@@ -26,6 +27,7 @@ Module.prototype.separable = function(callback) { | |||
| 26 | 27 | ||
| 27 | 28 | Module.prototype.disconnect = function() { | |
| 28 | 29 | this.reasons.length = 0; | |
| 30 | + this.lastId = this.id; | ||
| 29 | 31 | this.id = null; | |
| 30 | 32 | this.chunks.length = 0; | |
| 31 | 33 | DependenciesBlock.prototype.disconnect.call(this); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,7 +87,8 @@ Stats.prototype.toJson = function toJson(options, forToString) { | |||
| 87 | 87 | name: asset, | |
| 88 | 88 | size: compilation.assets[asset].size(), | |
| 89 | 89 | chunks: [], | |
| 90 | - chunkNames: [] | ||
| 90 | + chunkNames: [], | ||
| 91 | + emitted: compilation.assets[asset].emitted | ||
| 91 | 92 | }; | |
| 92 | 93 | assetsByFile[asset] = obj; | |
| 93 | 94 | return obj; | |
@@ -142,6 +143,7 @@ Stats.prototype.toJson = function toJson(options, forToString) { | |||
| 142 | 143 | obj.chunks = compilation.chunks.map(function(chunk) { | |
| 143 | 144 | var obj = { | |
| 144 | 145 | id: chunk.id, | |
| 146 | + rendered: chunk.rendered, | ||
| 145 | 147 | size: chunk.modules.reduce(function(size, module) { return size + module.size(); }, 0), | |
| 146 | 148 | names: chunk.name ? [chunk.name] : [], | |
| 147 | 149 | files: chunk.files.slice(), | |
@@ -277,16 +279,17 @@ Stats.jsonToString = function jsonToString(obj, useColors) { | |||
| 277 | 279 | newline(); | |
| 278 | 280 | } | |
| 279 | 281 | if(obj.assets) { | |
| 280 | - var t = [["Asset", "Size", "Chunks", "Chunk Names"]] | ||
| 282 | + var t = [["Asset", "Size", "Chunks", "", "Chunk Names"]] | ||
| 281 | 283 | obj.assets.forEach(function(asset) { | |
| 282 | 284 | t.push([ | |
| 283 | 285 | asset.name, | |
| 284 | 286 | asset.size, | |
| 285 | 287 | asset.chunks.join(", "), | |
| 288 | + asset.emitted ? "[emitted]" : "", | ||
| 286 | 289 | asset.chunkNames.join(", ") | |
| 287 | 290 | ]) | |
| 288 | 291 | }); | |
| 289 | - table(t, [green, normal, bold, normal], "rrrl"); | ||
| 292 | + table(t, [green, normal, bold, green, normal], "rrrll"); | ||
| 290 | 293 | } | |
| 291 | 294 | if(obj.chunks) { | |
| 292 | 295 | obj.chunks.forEach(function(chunk) { | |
@@ -306,11 +309,13 @@ Stats.jsonToString = function jsonToString(obj, useColors) { | |||
| 306 | 309 | normal(" "); | |
| 307 | 310 | normal(chunk.size); | |
| 308 | 311 | chunk.parents.forEach(function(id) { | |
| 309 | - normal(" "); | ||
| 310 | - normal("{"); | ||
| 312 | + normal(" {"); | ||
| 311 | 313 | yellow(id); | |
| 312 | - normal("} "); | ||
| 314 | + normal("}"); | ||
| 313 | 315 | }); | |
| 316 | + if(chunk.rendered) { | ||
| 317 | + green(" [rendered]"); | ||
| 318 | + } | ||
| 314 | 319 | newline(); | |
| 315 | 320 | if(chunk.modules) { | |
| 316 | 321 | chunk.modules.forEach(function(module) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments