Skip to content

Commit

Permalink
moved defaults for options.output into central place
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jan 6, 2016
1 parent 6bc4585 commit c838656
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
5 changes: 2 additions & 3 deletions lib/Compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,8 @@ Compilation.prototype.createModuleAssets = function createModuleAssets() {

Compilation.prototype.createChunkAssets = function createChunkAssets() {
var outputOptions = this.outputOptions;
var filename = outputOptions.filename || "[name].js";
var chunkFilename = outputOptions.chunkFilename ||
(filename.indexOf("[name]") >= 0 ? filename.replace("[name]", "[id]") : "[id]." + filename);
var filename = outputOptions.filename;
var chunkFilename = outputOptions.chunkFilename;
for(var i = 0; i < this.chunks.length; i++) {
var chunk = this.chunks[i];
chunk.files = [];
Expand Down
4 changes: 2 additions & 2 deletions lib/JsonpMainTemplatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
return source;
});
mainTemplate.plugin("require-ensure", function(_, chunk, hash) {
var filename = this.outputOptions.filename || "bundle.js";
var chunkFilename = this.outputOptions.chunkFilename || "[id]." + filename;
var filename = this.outputOptions.filename;
var chunkFilename = this.outputOptions.chunkFilename;
var chunkMaps = chunk.getChunkMaps();
var crossOriginLoading = this.outputOptions.crossOriginLoading;
var chunkLoadTimeout = this.outputOptions.chunkLoadTimeout || 120000;
Expand Down
9 changes: 9 additions & 0 deletions lib/WebpackOptionsDefaulter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author Tobias Koppers @sokra
*/
var OptionsDefaulter = require("./OptionsDefaulter");
var Template = require("./Template");

function WebpackOptionsDefaulter() {
OptionsDefaulter.call(this);
Expand All @@ -29,6 +30,7 @@ function WebpackOptionsDefaulter() {
this.set("module.wrappedContextRecursive", true);
this.set("module.wrappedContextCritical", false);

this.set("output.filename", "[name].js");
this.set("output.libraryTarget", "var");
this.set("output.path", "");
this.set("output.sourceMapFilename", "[file].map[query]");
Expand Down Expand Up @@ -75,4 +77,11 @@ WebpackOptionsDefaulter.prototype.process = function(options) {
else
options.resolve.mainFields = ["main"];
}

var outputOptions = options.output;
var filename = outputOptions.filename;
if(outputOptions.chunkFilename === undefined)
outputOptions.chunkFilename = filename.indexOf("[name]") >= 0 ? filename.replace("[name]", "[id]") : "[id]." + filename;
if(outputOptions.hotUpdateFunction === undefined)
outputOptions.hotUpdateFunction = Template.toIdentifier("webpackHotUpdate" + (outputOptions.library || ""));
};
4 changes: 2 additions & 2 deletions lib/node/NodeMainTemplatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ NodeMainTemplatePlugin.prototype.apply = function(mainTemplate) {
return source;
});
mainTemplate.plugin("require-ensure", function(_, chunk, hash) {
var filename = this.outputOptions.filename || "bundle.js";
var chunkFilename = this.outputOptions.chunkFilename || "[id]." + filename;
var filename = this.outputOptions.filename;
var chunkFilename = this.outputOptions.chunkFilename;
var chunkMaps = chunk.getChunkMaps();
var insertMoreModules = [
"var moreModules = chunk.modules, chunkIds = chunk.ids;",
Expand Down
4 changes: 2 additions & 2 deletions lib/webworker/WebWorkerMainTemplatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ WebWorkerMainTemplatePlugin.prototype.apply = function(mainTemplate) {
return source;
});
mainTemplate.plugin("require-ensure", function(_, chunk, hash) {
var filename = this.outputOptions.filename || "bundle.js";
var chunkFilename = this.outputOptions.chunkFilename || "[id]." + filename;
var filename = this.outputOptions.filename;
var chunkFilename = this.outputOptions.chunkFilename;
return this.asString([
"// \"1\" is the signal for \"already loaded\"",
"if(!installedChunks[chunkId]) {",
Expand Down

0 comments on commit c838656

Please sign in to comment.