Skip to content

Commit d394065

Browse files
committed
moved templates
1 parent d2908b1 commit d394065

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

lib/webpack.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ var fs = require("fs");
99

1010
var HASH_REGEXP = /\[hash\]/i;
1111

12-
var templateAsync = require("fs").readFileSync(path.join(__dirname, "templateAsync.js"));
13-
var templateSingle = require("fs").readFileSync(path.join(__dirname, "templateSingle.js"));
1412
/*
1513
webpack(context, moduleName, options, callback);
1614
webpack(context, moduleName, callback);
@@ -168,15 +166,15 @@ function webpack(context, moduleName, options, finalCallback) {
168166
chunkIds.sort(function(a,b) {
169167
return parseInt(b, 10) - parseInt(a, 10);
170168
});
169+
var template = getTemplate(options, {chunks: chunkIds.length > 1});
171170
var hash;
172171
try {
173172
hash = new (require("crypto").Hash)("md5");
174173
hash.update(JSON.stringify(options.libary || ""));
175174
hash.update(JSON.stringify(options.outputPostfix));
176175
hash.update(JSON.stringify(options.outputJsonpFunction));
177176
hash.update(JSON.stringify(options.scriptSrcPrefix));
178-
hash.update(templateAsync);
179-
hash.update(templateSingle);
177+
hash.update(template);
180178
hash.update("1");
181179
} catch(e) {
182180
callback(e);
@@ -204,7 +202,7 @@ function webpack(context, moduleName, options, finalCallback) {
204202
buffer.push("=\n");
205203
}
206204
if(chunkIds.length > 1) {
207-
buffer.push(templateAsync);
205+
buffer.push(template);
208206
buffer.push("/******/({a:");
209207
buffer.push(JSON.stringify(options.outputPostfix.replace(HASH_REGEXP, hash)));
210208
buffer.push(",b:");
@@ -213,7 +211,7 @@ function webpack(context, moduleName, options, finalCallback) {
213211
buffer.push(JSON.stringify(options.scriptSrcPrefix.replace(HASH_REGEXP, hash)));
214212
buffer.push(",\n");
215213
} else {
216-
buffer.push(templateSingle);
214+
buffer.push(template);
217215
buffer.push("/******/({\n");
218216
}
219217
} else {
@@ -331,7 +329,7 @@ function webpack(context, moduleName, options, finalCallback) {
331329
buffer.push(options.libary);
332330
buffer.push("=\n");
333331
}
334-
buffer.push(templateSingle);
332+
buffer.push(getTemplate(options, {chunks: false}));
335333
buffer.push("/******/({\n");
336334
buffer.push(writeChunk(depTree, options));
337335
buffer.push("/******/})");
@@ -347,6 +345,16 @@ function webpack(context, moduleName, options, finalCallback) {
347345
return options.events;
348346
}
349347

348+
function getTemplate(options, templateOptions) {
349+
if(options.template) {
350+
if(typeof options.template === "string")
351+
return require(options.template)(options, templateOptions);
352+
else
353+
return options.template(options, templateOptions);
354+
} else
355+
return require("../templates/browser")(options, templateOptions);
356+
}
357+
350358
function uglify(input, filename) {
351359
var uglify = require("uglify-js");
352360
try {

templates/browser.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function(options, templateOptions) {
2+
if(templateOptions.chunks) {
3+
return require("fs").readFileSync(require("path").join(__dirname, "browserAsync.js"));
4+
} else {
5+
return require("fs").readFileSync(require("path").join(__dirname, "browserSingle.js"));
6+
}
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
/******/ head.appendChild(script);
2626
/******/ }
2727
/******/ };
28+
/******/ require.modules = modules;
2829
/******/ window[modules.b] = function(chunkId, moreModules) {
2930
/******/ for(var moduleId in moreModules)
3031
/******/ modules[moduleId] = moreModules[moduleId];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
/******/ require.ensure = function(chunkId, callback) {
1414
/******/ callback(require);
1515
/******/ };
16+
/******/ require.modules = modules;
1617
/******/ return require(0);
1718
/******/})

0 commit comments

Comments
 (0)