From 327a99007025623e42e924bb5a79507448aeb399 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 19 Jun 2013 11:53:03 +0200 Subject: [PATCH] fixed bugs --- lib/ChunkTemplate.js | 7 ++----- lib/Compilation.js | 6 +++--- lib/JsonpChunkTemplate.js | 2 +- lib/JsonpMainTemplate.js | 8 ++++++-- lib/MainTemplate.js | 22 +++++++++++++++------- lib/RecordIdsPlugin.js | 2 ++ lib/WebpackOptionsApply.js | 6 +++++- lib/optimize/DedupePlugin.js | 2 +- lib/webworker/WebWorkerMainTemplate.js | 6 +++++- package.json | 2 +- 10 files changed, 41 insertions(+), 22 deletions(-) diff --git a/lib/ChunkTemplate.js b/lib/ChunkTemplate.js index 37d7f8398..3ea25ed66 100644 --- a/lib/ChunkTemplate.js +++ b/lib/ChunkTemplate.js @@ -35,9 +35,6 @@ ChunkTemplate.prototype.renderFooter = function(chunk) { }; ChunkTemplate.prototype.updateHash = function(hash) { - hash.update("template"); - hash.update("jsonp"); - hash.update("2"); - hash.update(this.outputOptions.jsonpFunction + ""); - hash.update(this.outputOptions.library + ""); + hash.update("ChunkTemplate"); + hash.update("1"); }; \ No newline at end of file diff --git a/lib/Compilation.js b/lib/Compilation.js index 7f8f5fe95..3553cf6ce 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -541,7 +541,7 @@ Compilation.prototype.createChunkAssets = function createChunkAssets() { if(this.cache && this.cache["c" + chunk.id + chunk.name] && this.cache["c" + chunk.id + chunk.name].hash == hash) { source = this.cache["c" + chunk.id + chunk.name].source; } else { - source = this.mainTemplate.render(hash, chunk, this.moduleTemplate, this.dependencyTemplates); + source = this.mainTemplate.render(this.hash, chunk, this.moduleTemplate, this.dependencyTemplates); if(this.cache) { this.cache["c" + chunk.id + chunk.name] = { hash: hash, @@ -572,7 +572,7 @@ Compilation.prototype.createChunkAssets = function createChunkAssets() { } this.assets[ file = chunkFilename - .replace(Template.REGEXP_HASH, hash) + .replace(Template.REGEXP_HASH, this.hash) .replace(Template.REGEXP_CHUNKHASH, chunk.renderedHash) .replace(Template.REGEXP_ID, chunk.id) ] = source; @@ -582,7 +582,7 @@ Compilation.prototype.createChunkAssets = function createChunkAssets() { this.assets[ file = namedChunkFilename .replace(Template.REGEXP_CHUNKHASH, chunk.renderedHash) - .replace(Template.REGEXP_HASH, hash) + .replace(Template.REGEXP_HASH, this.hash) .replace(Template.REGEXP_ID, chunk.id) .replace(Template.REGEXP_NAME, chunk.name || "") ] = source; diff --git a/lib/JsonpChunkTemplate.js b/lib/JsonpChunkTemplate.js index c3ea03166..762738b2b 100644 --- a/lib/JsonpChunkTemplate.js +++ b/lib/JsonpChunkTemplate.js @@ -25,7 +25,7 @@ JsonpChunkTemplate.prototype.renderFooter = function(chunk) { JsonpChunkTemplate.prototype.updateHash = function(hash) { ChunkTemplate.prototype.updateHash.call(this, hash); - hash.update("jsonp"); + hash.update("JsonpChunkTemplate"); hash.update("3"); hash.update(this.outputOptions.jsonpFunction + ""); hash.update(this.outputOptions.library + ""); diff --git a/lib/JsonpMainTemplate.js b/lib/JsonpMainTemplate.js index feecf26ae..0c0829347 100644 --- a/lib/JsonpMainTemplate.js +++ b/lib/JsonpMainTemplate.js @@ -54,8 +54,8 @@ JsonpMainTemplate.prototype.renderRequireEnsure = function(hash, chunk) { "script.charset = 'utf-8';", "script.src = modules.c + " + JSON.stringify(chunkFilename - .replace(Template.REGEXP_HASH, hash) .replace(Template.REGEXP_NAME, "")) + .replace(Template.REGEXP_HASH, "\" + " + this.renderCurrentHashCode(hash) + " + \"") .replace(Template.REGEXP_CHUNKHASH, "\" + " + JSON.stringify(chunkHashMap) + "[chunkId] + \"") .replace(Template.REGEXP_ID, "\" + chunkId + \"") + ";", "head.appendChild(script);" @@ -88,7 +88,7 @@ JsonpMainTemplate.prototype.renderInit = function(hash, chunk) { this.indent(this.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")), "}", "while(callbacks.length)", - this.indent("callbacks.shift().call(null, require);"), + this.indent("callbacks.shift().call(null, " + this.requireFn + ");"), ]), "};" ); @@ -96,6 +96,10 @@ JsonpMainTemplate.prototype.renderInit = function(hash, chunk) { return buf; }; +JsonpMainTemplate.prototype.renderCurrentHashCode = function(hash) { + return JSON.stringify(hash); +}; + JsonpMainTemplate.prototype.updateHash = function(hash) { MainTemplate.prototype.updateHash.call(this, hash); hash.update("jsonp"); diff --git a/lib/MainTemplate.js b/lib/MainTemplate.js index cc9db2cc8..851c7aa2f 100644 --- a/lib/MainTemplate.js +++ b/lib/MainTemplate.js @@ -27,7 +27,7 @@ MainTemplate.prototype.render = function(hash, chunk, moduleTemplate, dependency buf.push(this.asString(this.renderInit(hash, chunk))); buf.push(""); buf.push("// Load entry module and return exports"); - buf.push("return " + this.requireFn + "(0);"); + buf.push("return " + this.renderRequireFunctionForModule(hash, chunk, "0") + "(0);"); var source = new ConcatSource(); source.add("/******/ (function(modules) { // webpackBootstrap\n"); source.add(new PrefixSource("/******/ \t", new OriginalSource(this.asString(buf), "webpackBootstrap " + hash))); @@ -91,15 +91,11 @@ MainTemplate.prototype.renderRequireContent = function(hash, chunk) { "", "// Create a new module (and put it into the cache)", "var module = installedModules[moduleId] = {", - this.indent([ - "exports: {},", - "id: moduleId,", - "loaded: false" - ]), + this.indent(this.renderModule(hash, chunk, "moduleId")), "};", "", "// Execute the module function", - "modules[moduleId].call(null, module, module.exports, " + this.requireFn + ");", + "modules[moduleId].call(null, module, module.exports, " + this.renderRequireFunctionForModule(hash, chunk, "moduleId") + ");", "", "// Flag the module as loaded", "module.loaded = true;", @@ -109,6 +105,18 @@ MainTemplate.prototype.renderRequireContent = function(hash, chunk) { ]; }; +MainTemplate.prototype.renderRequireFunctionForModule = function(hash, chunk, varModuleId) { + return this.requireFn; +}; + +MainTemplate.prototype.renderModule = function(hash, chunk, varModuleId) { + return [ + "exports: {},", + "id: moduleId,", + "loaded: false" + ]; +}; + MainTemplate.prototype.renderRequireExtensions = function(hash, chunk) { var buf = []; if(chunk.chunks.length == 0) { diff --git a/lib/RecordIdsPlugin.js b/lib/RecordIdsPlugin.js index 8dc78e994..4909d7dcb 100644 --- a/lib/RecordIdsPlugin.js +++ b/lib/RecordIdsPlugin.js @@ -25,6 +25,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) { if(module.id !== null) return; var identifier = module.identifier(); var id = records.modules.byIdentifier[identifier]; + if(id === undefined) return; if(usedIds[id]) return; usedIds[id] = true; module.id = id; @@ -68,6 +69,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) { if(chunk.id !== null) return; if(!chunk.name) return; var id = records.chunks.byName[chunk.name]; + if(id === undefined) return; if(usedIds[id]) return; usedIds[id] = true; chunk.id = id; diff --git a/lib/WebpackOptionsApply.js b/lib/WebpackOptionsApply.js index 446baa741..b3710cd42 100644 --- a/lib/WebpackOptionsApply.js +++ b/lib/WebpackOptionsApply.js @@ -92,8 +92,10 @@ WebpackOptionsApply.prototype.process = function(options, compiler) { ); break; } - if(options.output.library || options.output.libraryTarget != "var") + if(options.output.library || options.output.libraryTarget != "var") { compiler.apply(new LibraryTemplatePlugin(options.output.library, options.output.libraryTarget)); + } + if(options.devtool == "eval") compiler.apply(new EvalDevToolModulePlugin()); else if(options.devtool == "sourcemap" || options.devtool == "source-map") @@ -102,6 +104,7 @@ WebpackOptionsApply.prototype.process = function(options, compiler) { options.devtool == "inline-sourcemap" || options.devtool == "inline-source-map") compiler.apply(new SourceMapDevToolPlugin(options.context)); + function itemToPlugin(item, name) { if(Array.isArray(item)) return new MultiEntryPlugin(options.context, item, name); @@ -115,6 +118,7 @@ WebpackOptionsApply.prototype.process = function(options, compiler) { compiler.apply(itemToPlugin(options.entry[name], name)); }); } + if(options.prefetch) { options.prefetch.map(function(request) { compiler.apply(new PrefetchPlugin(options.context, request)); diff --git a/lib/optimize/DedupePlugin.js b/lib/optimize/DedupePlugin.js index 3104ee91f..676491564 100644 --- a/lib/optimize/DedupePlugin.js +++ b/lib/optimize/DedupePlugin.js @@ -190,7 +190,7 @@ function DedupModuleTemplateDecorator(template) { } DedupModuleTemplateDecorator.prototype.render = function(module, dependencyTemplates, chunk) { - if(!module.rootDuplicatesChunks) return this.template.render(module, dependencyTemplates, chunk); + if(!module.rootDuplicatesChunks || !chunk) return this.template.render(module, dependencyTemplates, chunk); var chunkIndex = module.rootDuplicatesChunks.indexOf(chunk); if(!module.rootDuplicates || !module.rootDuplicates[chunkIndex]) return this.template.render(module, dependencyTemplates, chunk); var rootDuplicates = module.rootDuplicates[chunkIndex]; diff --git a/lib/webworker/WebWorkerMainTemplate.js b/lib/webworker/WebWorkerMainTemplate.js index ff04456a1..5079f9c90 100644 --- a/lib/webworker/WebWorkerMainTemplate.js +++ b/lib/webworker/WebWorkerMainTemplate.js @@ -34,8 +34,8 @@ WebWorkerMainTemplate.prototype.renderRequireEnsure = function(hash, chunk) { this.indent([ "importScripts(" + JSON.stringify(chunkFilename - .replace(Template.REGEXP_HASH, hash) .replace(Template.REGEXP_NAME, "")) + .replace(Template.REGEXP_HASH, "\" + " + this.renderCurrentHashCode(hash) + " + \"") .replace(Template.REGEXP_ID, "\" + chunkId + \"") + ");" ]), "}", @@ -62,6 +62,10 @@ WebWorkerMainTemplate.prototype.renderInit = function(hash, chunk) { return buf; }; +WebWorkerMainTemplate.prototype.renderCurrentHashCode = function(hash) { + return JSON.stringify(hash); +}; + WebWorkerMainTemplate.prototype.updateHash = function(hash) { MainTemplate.prototype.updateHash.call(this, hash); hash.update("webworker"); diff --git a/package.json b/package.json index 2b95517ff..dec6b8c82 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webpack", - "version": "0.10.0-beta24", + "version": "0.10.0-beta25", "author": "Tobias Koppers @sokra", "description": "Packs CommonJs/AMD/Labeled Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.", "dependencies": {