SourceMap support
This commit is contained in:
parent
6c3f51e6d9
commit
0de7c73ad8
|
@ -17,7 +17,7 @@ Check the [documentation](https://github.com/webpack/docs/wiki) if you want to k
|
|||
|
||||
# Examples
|
||||
|
||||
Take a look at the `examples` folder.
|
||||
Take a look at the [`examples`](https://github.com/webpack/webpack/tree/master/examples) folder.
|
||||
|
||||
# Features
|
||||
|
||||
|
@ -25,6 +25,7 @@ Take a look at the `examples` folder.
|
|||
* loaders run in node.js and can do a bunch of stuff
|
||||
* option to name your file with a hash of the content
|
||||
* watch mode
|
||||
* SourceUrl and SourceMap support
|
||||
* plugin system, extend webpack or build a complete different compiler
|
||||
* interfaces
|
||||
* CLI with arguments
|
||||
|
|
|
@ -19,6 +19,10 @@ module.exports = function(optimist) {
|
|||
|
||||
.string("output-chunk-file").describe("output-chunk-file")
|
||||
|
||||
.string("output-named-chunk-file").describe("output-named-chunk-file")
|
||||
|
||||
.string("output-source-map-file").describe("output-source-map-file")
|
||||
|
||||
.string("output-public-path").describe("output-public-path")
|
||||
|
||||
.boolean("output-pathinfo").describe("output-pathinfo")
|
||||
|
@ -53,5 +57,9 @@ module.exports = function(optimist) {
|
|||
|
||||
.string("plugin").describe("plugin")
|
||||
|
||||
.boolean("bail").describe("bail");
|
||||
.boolean("bail").describe("bail")
|
||||
|
||||
.boolean("d").describe("d", "shortcut for --debug --devtool sourcemap --output-pathinfo")
|
||||
|
||||
.boolean("p").describe("p", "shortcut for --optimize-minimize");
|
||||
};
|
|
@ -7,6 +7,16 @@ module.exports = function(optimist, argv, convertOptions) {
|
|||
|
||||
var options = {};
|
||||
|
||||
// Shortcuts
|
||||
if(argv.d) {
|
||||
argv.debug = true;
|
||||
argv["output-pathinfo"] = true;
|
||||
if(!argv.devtool) argv.devtool = "sourcemap";
|
||||
}
|
||||
if(argv.p) {
|
||||
argv["optimize-minimize"] = true;
|
||||
}
|
||||
|
||||
function ifArg(name, fn, init) {
|
||||
if(Array.isArray(argv[name])) {
|
||||
if(init) init();
|
||||
|
@ -148,6 +158,11 @@ module.exports = function(optimist, argv, convertOptions) {
|
|||
options.output.namedChunkFilename = value;
|
||||
});
|
||||
|
||||
ifArg("output-source-map-file", function(value) {
|
||||
ensureObject(options, "output");
|
||||
options.output.sourceMapFilename = value;
|
||||
});
|
||||
|
||||
ifArg("output-public-path", function(value) {
|
||||
ensureObject(options, "output");
|
||||
options.output.publicPath = value;
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
||||
var Template = require("./Template");
|
||||
|
||||
function ChunkTemplate(outputOptions) {
|
||||
Template.call(this, outputOptions);
|
||||
}
|
||||
|
||||
module.exports = ChunkTemplate;
|
||||
|
||||
ChunkTemplate.prototype = Object.create(Template.prototype);
|
||||
ChunkTemplate.prototype.render = function(chunk, moduleTemplate, dependencyTemplates) {
|
||||
var source = new ConcatSource();
|
||||
source.add(this.asString(this.renderHeader(chunk)));
|
||||
chunk.modules.forEach(function(module, idx) {
|
||||
if(idx != 0) source.add(",\n");
|
||||
source.add("\n/***/ " + module.id + ":\n");
|
||||
source.add(moduleTemplate.render(module, dependencyTemplates));
|
||||
});
|
||||
source.add("\n\n");
|
||||
source.add(this.asString(this.renderFooter(chunk)));
|
||||
return source;
|
||||
};
|
||||
|
||||
ChunkTemplate.prototype.renderHeader = function(chunk) {
|
||||
return ["{\n"];
|
||||
};
|
||||
|
||||
ChunkTemplate.prototype.renderFooter = function(chunk) {
|
||||
return ["}"];
|
||||
};
|
||||
|
||||
ChunkTemplate.prototype.updateHash = function(hash) {
|
||||
hash.update("template");
|
||||
hash.update("jsonp");
|
||||
hash.update("2");
|
||||
hash.update(this.outputOptions.jsonpFunction + "");
|
||||
hash.update(this.outputOptions.library + "");
|
||||
};
|
|
@ -14,6 +14,7 @@ var Module = require("./Module");
|
|||
var ArrayMap = require("./ArrayMap");
|
||||
var Chunk = require("./Chunk");
|
||||
var Stats = require("./Stats");
|
||||
var Template = require("./Template");
|
||||
|
||||
function Compilation(compiler) {
|
||||
Tapable.call(this);
|
||||
|
@ -77,6 +78,10 @@ Compilation.prototype.getModule = function(module) {
|
|||
return this._modules[identifier];
|
||||
};
|
||||
|
||||
Compilation.prototype.findModule = function(identifier) {
|
||||
return this._modules[identifier];
|
||||
};
|
||||
|
||||
Compilation.prototype.buildModule = function(module, callback) {
|
||||
this.applyPlugins("build-module", module);
|
||||
module.build(this.options, this, this.resolvers.normal, this.inputFileSystem, function(err) {
|
||||
|
@ -278,6 +283,7 @@ Compilation.prototype.seal = function seal(callback) {
|
|||
this.summarizeDependencies();
|
||||
this.applyPluginsAsync("optimize-chunk-assets", this.chunks, function(err) {
|
||||
if(err) return callback(err);
|
||||
this.applyPlugins("after-optimize-chunk-assets", this.chunks);
|
||||
this.applyPluginsAsync("optimize-assets", this.assets, function(err) {
|
||||
if(err) return callback(err);
|
||||
this.applyPlugins("after-optimize-assets", this.assets);
|
||||
|
@ -457,13 +463,10 @@ Compilation.prototype.summarizeDependencies = function summarizeDependencies() {
|
|||
this.contextDependencies = filterDups(this.contextDependencies);
|
||||
};
|
||||
|
||||
var REGEXP_ID = /\[id\]/g;
|
||||
var REGEXP_NAME = /\[name\]/g;
|
||||
var REGEXP_HASH = /\[hash\]/g;
|
||||
Compilation.prototype.createChunkAssets = function createChunkAssets() {
|
||||
var outputOptions = this.outputOptions || {};
|
||||
var filename = outputOptions.filename || "bundle.js";
|
||||
var chunkFilename = outputOptions.chunkFilename || "[id]." + filename.replace(REGEXP_NAME, "");
|
||||
var chunkFilename = outputOptions.chunkFilename || "[id]." + filename.replace(Template.REGEXP_NAME, "");
|
||||
var namedChunkFilename = outputOptions.namedChunkFilename || null;
|
||||
var hash = new (require("crypto").Hash)("md5");
|
||||
this.mainTemplate.updateHash(hash);
|
||||
|
@ -479,7 +482,9 @@ Compilation.prototype.createChunkAssets = function createChunkAssets() {
|
|||
var module = this.modules[i];
|
||||
if(module.assets) {
|
||||
Object.keys(module.assets).forEach(function(name) {
|
||||
this.assets[name.replace(REGEXP_HASH, hash)] = module.assets[name];
|
||||
var file = name.replace(Template.REGEXP_HASH, hash);
|
||||
this.assets[file] = module.assets[name];
|
||||
this.applyPlugins("module-asset", module, file);
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
|
@ -490,15 +495,32 @@ Compilation.prototype.createChunkAssets = function createChunkAssets() {
|
|||
var file;
|
||||
if(chunk.entry) {
|
||||
source = this.mainTemplate.render(hash, chunk, this.moduleTemplate, this.dependencyTemplates);
|
||||
this.assets[file = filename.replace(REGEXP_HASH, hash).replace(REGEXP_ID, chunk.id).replace(REGEXP_NAME, chunk.name || "")] = source;
|
||||
this.assets[
|
||||
file = filename
|
||||
.replace(Template.REGEXP_HASH, hash)
|
||||
.replace(Template.REGEXP_ID, chunk.id)
|
||||
.replace(Template.REGEXP_NAME, chunk.name || "")
|
||||
] = source;
|
||||
chunk.files.push(file);
|
||||
this.applyPlugins("chunk-asset", chunk, file);
|
||||
} else {
|
||||
source = this.chunkTemplate.render(chunk, this.moduleTemplate, this.dependencyTemplates);
|
||||
this.assets[file = chunkFilename.replace(REGEXP_HASH, hash).replace(REGEXP_ID, chunk.id)] = source;
|
||||
this.assets[
|
||||
file = chunkFilename
|
||||
.replace(Template.REGEXP_HASH, hash)
|
||||
.replace(Template.REGEXP_ID, chunk.id)
|
||||
] = source;
|
||||
chunk.files.push(file);
|
||||
this.applyPlugins("chunk-asset", chunk, file);
|
||||
if(namedChunkFilename && chunk.name) {
|
||||
this.assets[file = namedChunkFilename.replace(REGEXP_HASH, hash).replace(REGEXP_ID, chunk.id).replace(REGEXP_NAME, chunk.name || "")] = source;
|
||||
this.assets[
|
||||
file = namedChunkFilename
|
||||
.replace(Template.REGEXP_HASH, hash)
|
||||
.replace(Template.REGEXP_ID, chunk.id)
|
||||
.replace(Template.REGEXP_NAME, chunk.name || "")
|
||||
] = source;
|
||||
chunk.files.push(file);
|
||||
this.applyPlugins("chunk-asset", chunk, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ Compiler.prototype.emitAssets = function(compilation, callback) {
|
|||
|
||||
require("async").forEach(Object.keys(compilation.assets), function(file, callback) {
|
||||
|
||||
if(file.indexOf("/")) {
|
||||
if(file.indexOf("/") >= 0) {
|
||||
var idx = file.lastIndexOf("/");
|
||||
var dir = file.substr(0, idx);
|
||||
this.outputFileSystem.mkdirp(this.outputFileSystem.join(this.outputPath, dir), writeOut.bind(this));
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var Module = require("./Module");
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var OriginalSource = require("webpack-core/lib/OriginalSource");
|
||||
|
||||
function ContextModule(resolveDependencies, context, recursive, regExp, addon) {
|
||||
Module.call(this);
|
||||
|
@ -97,7 +97,7 @@ ContextModule.prototype.source = function(dependencyTemplates, outputOptions, re
|
|||
"webpackContext.resolve = webpackContextResolve;\n",
|
||||
"module.exports = webpackContext;\n",
|
||||
];
|
||||
return new RawSource(str.join(""));
|
||||
return new OriginalSource(str.join(""), this.identifier());
|
||||
};
|
||||
|
||||
ContextModule.prototype.size = function() {
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var ReplaceSource = require("./ReplaceSource");
|
||||
var StringSource = require("webpack-core/lib/RawSource");
|
||||
var ReplaceSource = require("webpack-core/lib/ReplaceSource");
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
|
||||
function DependenciesBlockVariable(name, expression, dependencies) {
|
||||
this.name = name;
|
||||
|
@ -21,7 +21,7 @@ DependenciesBlockVariable.prototype.updateHash = function(hash) {
|
|||
};
|
||||
|
||||
DependenciesBlockVariable.prototype.expressionSource = function(dependencyTemplates, outputOptions, requestShortener) {
|
||||
var source = new ReplaceSource(new StringSource(this.expression));
|
||||
var source = new ReplaceSource(new RawSource(this.expression));
|
||||
this.dependencies.forEach(function(dep) {
|
||||
var template = dependencyTemplates.get(dep.Class);
|
||||
if(!template) throw new Error("No template for dependency: " + dep.Class.name);
|
||||
|
|
|
@ -18,7 +18,7 @@ EvalDevToolModuleTemplateDecorator.prototype.render = function(module, dependenc
|
|||
"// WEBPACK FOOTER",
|
||||
"// module.id = " + module.id,
|
||||
"// module.readableIdentifier = " + module.readableIdentifier(requestShortener),
|
||||
"//@ sourceURL=webpack-module:///" + encodeURI(module.readableIdentifier(requestShortener) + "(" + module.id + ")").replace(/%2F/g, "/").replace(/%20/g, "_").replace(/%5E/g, "^").replace(/%5C/g, "\\").replace(/\?/, "%3F").replace(/^\//, "")
|
||||
"//@ sourceURL=webpack-module:///" + encodeURI(module.readableIdentifier(requestShortener)).replace(/%2F/g, "/").replace(/%20/g, "_").replace(/%5E/g, "^").replace(/%5C/g, "\\").replace(/\?/, "%3F").replace(/^\//, "")
|
||||
].join("\n");
|
||||
return new RawSource("eval(" + JSON.stringify(content + footer) + ");" );
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
||||
|
||||
function FunctionModuleTemplate(outputOptions, requestShortener) {
|
||||
this.outputOptions = outputOptions || {};
|
||||
|
@ -11,18 +11,17 @@ function FunctionModuleTemplate(outputOptions, requestShortener) {
|
|||
module.exports = FunctionModuleTemplate;
|
||||
|
||||
FunctionModuleTemplate.prototype.render = function(module, dependencyTemplates) {
|
||||
var buf = [];
|
||||
var source = new ConcatSource();
|
||||
if(this.outputOptions.pathinfo) {
|
||||
var req = module.readableIdentifier(this.requestShortener);
|
||||
buf.push("/*!****" + req.replace(/./g, "*") + "****!*\\\n");
|
||||
buf.push(" !*** " + req.replace(/\*\//g, "*_/") + " ***!\n");
|
||||
buf.push(" \\****" + req.replace(/./g, "*") + "****/\n");
|
||||
source.add("/*!****" + req.replace(/./g, "*") + "****!*\\\n");
|
||||
source.add(" !*** " + req.replace(/\*\//g, "*_/") + " ***!\n");
|
||||
source.add(" \\****" + req.replace(/./g, "*") + "****/\n");
|
||||
}
|
||||
buf.push("/***/ function(module, exports, require) {\n\n");
|
||||
var source = module.source(dependencyTemplates, this.outputOptions, this.requestShortener);
|
||||
buf.push("\t" + source.source().replace(/\r?\n/g, "\n\t"));
|
||||
buf.push("\n\n/***/ }");
|
||||
return new RawSource(buf.join(""));
|
||||
source.add("/***/ function(module, exports, require) {\n\n");
|
||||
source.add(module.source(dependencyTemplates, this.outputOptions, this.requestShortener));
|
||||
source.add("\n\n/***/ }");
|
||||
return source;
|
||||
};
|
||||
|
||||
FunctionModuleTemplate.prototype.updateHash = function(hash) {
|
||||
|
|
|
@ -2,30 +2,31 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var ChunkTemplate = require("./ChunkTemplate");
|
||||
|
||||
function JsonpChunkTemplate(outputOptions) {
|
||||
this.outputOptions = outputOptions || {};
|
||||
ChunkTemplate.call(this, outputOptions);
|
||||
}
|
||||
module.exports = JsonpChunkTemplate;
|
||||
|
||||
JsonpChunkTemplate.prototype.render = function(chunk, moduleTemplate, dependencyTemplates) {
|
||||
JsonpChunkTemplate.prototype = Object.create(ChunkTemplate.prototype);
|
||||
JsonpChunkTemplate.prototype.renderHeader = function(chunk) {
|
||||
var buf = ChunkTemplate.prototype.renderHeader.call(this, chunk);
|
||||
var jsonpFunction = this.outputOptions.jsonpFunction || ("webpackJsonp" + (this.outputOptions.library || ""));
|
||||
var buf = [];
|
||||
buf.push(jsonpFunction + "(" + JSON.stringify(chunk.ids) + ", {\n");
|
||||
chunk.modules.forEach(function(module, idx) {
|
||||
if(idx != 0) buf.push(",\n");
|
||||
buf.push("\n/***/ " + module.id + ":\n");
|
||||
var source = moduleTemplate.render(module, dependencyTemplates);
|
||||
buf.push(source.source());
|
||||
});
|
||||
buf.push("\n\n})");
|
||||
return new RawSource(buf.join(""));
|
||||
buf.unshift(jsonpFunction + "(" + JSON.stringify(chunk.ids) + ",");
|
||||
return buf;
|
||||
};
|
||||
|
||||
JsonpChunkTemplate.prototype.renderFooter = function(chunk) {
|
||||
var buf = ChunkTemplate.prototype.renderFooter.call(this, chunk);
|
||||
buf.push(")");
|
||||
return buf;
|
||||
};
|
||||
|
||||
JsonpChunkTemplate.prototype.updateHash = function(hash) {
|
||||
ChunkTemplate.prototype.updateHash.call(this, hash);
|
||||
hash.update("jsonp");
|
||||
hash.update("2");
|
||||
hash.update("3");
|
||||
hash.update(this.outputOptions.jsonpFunction + "");
|
||||
hash.update(this.outputOptions.library + "");
|
||||
};
|
|
@ -2,101 +2,97 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var StringSource = require("webpack-core/lib/RawSource");
|
||||
var MainTemplate = require("./MainTemplate");
|
||||
var Template = require("./Template");
|
||||
|
||||
function JsonpMainTemplate(outputOptions) {
|
||||
this.outputOptions = outputOptions || {};
|
||||
MainTemplate.call(this, outputOptions);
|
||||
}
|
||||
module.exports = JsonpMainTemplate;
|
||||
|
||||
var REGEXP_HASH = /\[hash\]/i;
|
||||
var REGEXP_NAME = /\[name\]/g;
|
||||
var REGEXP_ID = /\[id\]/i;
|
||||
JsonpMainTemplate.prototype.render = function(hash, chunk, moduleTemplate, dependencyTemplates) {
|
||||
var jsonpFunction = this.outputOptions.jsonpFunction || ("webpackJsonp" + (this.outputOptions.library || ""));
|
||||
var publicPath = this.outputOptions.publicPath || "";
|
||||
JsonpMainTemplate.prototype = Object.create(MainTemplate.prototype);
|
||||
|
||||
JsonpMainTemplate.prototype.renderLocalVars = function(hash, chunk) {
|
||||
var buf = MainTemplate.prototype.renderLocalVars.call(this, hash, chunk);
|
||||
if(chunk.chunks.length > 0) {
|
||||
buf.push(
|
||||
"",
|
||||
"// object to store loaded and loading chunks",
|
||||
'// "0" means "already loaded"',
|
||||
'// Array means "loading", array contains callbacks',
|
||||
"var installedChunks = {0:0};"
|
||||
);
|
||||
}
|
||||
return buf;
|
||||
};
|
||||
|
||||
JsonpMainTemplate.prototype.renderRequireEnsure = function(hash, chunk) {
|
||||
var filename = this.outputOptions.filename || "bundle.js";
|
||||
var chunkFilename = this.outputOptions.chunkFilename || "[id]." + filename;
|
||||
var buf = [];
|
||||
function addLine(indent, line) {
|
||||
buf.push("/******/ ");
|
||||
for(var i = 0; i < indent; i++)
|
||||
buf.push("\t");
|
||||
buf.push(line);
|
||||
buf.push("\n");
|
||||
}
|
||||
function addRequireFunc(i) {
|
||||
addLine(i+0, "function require(moduleId) {");
|
||||
addLine(i+1, "if(installedModules[moduleId])");
|
||||
addLine(i+2, "return installedModules[moduleId].exports;");
|
||||
addLine(i+1, "var module = installedModules[moduleId] = {");
|
||||
addLine(i+2, "exports: {},");
|
||||
addLine(i+2, "id: moduleId,");
|
||||
addLine(i+2, "loaded: false");
|
||||
addLine(i+1, "};");
|
||||
addLine(i+1, "modules[moduleId].call(null, module, module.exports, require);");
|
||||
addLine(i+1, "module.loaded = true;");
|
||||
addLine(i+1, "return module.exports;");
|
||||
addLine(i+0, "}");
|
||||
}
|
||||
addLine(0, "(function webpackBootstrap(modules) {");
|
||||
addLine(1, "var installedModules = {};");
|
||||
if(chunk.chunks.length > 0)
|
||||
addLine(1, "var installedChunks = {0:0};");
|
||||
addRequireFunc(1);
|
||||
addLine(1, "require.e = function requireEnsure(chunkId, callback) {");
|
||||
if(chunk.chunks.length == 0) {
|
||||
addLine(2, "callback.call(null, require);");
|
||||
} else {
|
||||
addLine(2, "if(installedChunks[chunkId] === 0) return callback.call(null, require);");
|
||||
addLine(2, "if(installedChunks[chunkId] !== undefined)");
|
||||
addLine(3, "installedChunks[chunkId].push(callback);");
|
||||
addLine(2, "else {");
|
||||
addLine(3, "installedChunks[chunkId] = [callback];");
|
||||
addLine(3, "var head = document.getElementsByTagName('head')[0];");
|
||||
addLine(3, "var script = document.createElement('script');");
|
||||
addLine(3, "script.type = 'text/javascript';");
|
||||
addLine(3, "script.charset = 'utf-8';");
|
||||
addLine(3, "script.src = modules.c+" + JSON.stringify(chunkFilename.replace(REGEXP_HASH, hash).replace(REGEXP_NAME, "")).replace(REGEXP_ID, "\"+chunkId+\"") + ";");
|
||||
addLine(3, "head.appendChild(script);");
|
||||
addLine(2, "}");
|
||||
}
|
||||
addLine(1, "};");
|
||||
addLine(1, "require.modules = modules;");
|
||||
addLine(1, "require.cache = installedModules;");
|
||||
return [
|
||||
"// \"0\" is the signal for \"already loaded\"",
|
||||
"if(installedChunks[chunkId] === 0)",
|
||||
this.indent("return callback.call(null, require);"),
|
||||
"",
|
||||
"// an array means \"currently loading\".",
|
||||
"if(installedChunks[chunkId] !== undefined) {",
|
||||
this.indent("installedChunks[chunkId].push(callback);"),
|
||||
"} else {",
|
||||
this.indent([
|
||||
"// start chunk loading",
|
||||
"installedChunks[chunkId] = [callback];",
|
||||
"var head = document.getElementsByTagName('head')[0];",
|
||||
"var script = document.createElement('script');",
|
||||
"script.type = 'text/javascript';",
|
||||
"script.charset = 'utf-8';",
|
||||
"script.src = modules.c + " +
|
||||
JSON.stringify(chunkFilename
|
||||
.replace(Template.REGEXP_HASH, hash)
|
||||
.replace(Template.REGEXP_NAME, ""))
|
||||
.replace(Template.REGEXP_ID, "\" + chunkId + \"") + ";",
|
||||
"head.appendChild(script);"
|
||||
]),
|
||||
"}"
|
||||
];
|
||||
};
|
||||
|
||||
JsonpMainTemplate.prototype.renderInit = function(hash, chunk) {
|
||||
var buf = MainTemplate.prototype.renderInit.call(this, hash, chunk);
|
||||
if(chunk.chunks.length > 0) {
|
||||
addLine(1, "window[" + JSON.stringify(jsonpFunction) + "] = function webpackJsonpCallback(chunkIds, moreModules) {");
|
||||
addLine(2, "var moduleId, chunkId, callbacks = [];");
|
||||
addLine(2, "while(chunkIds.length) {");
|
||||
addLine(3, "chunkId = chunkIds.shift();");
|
||||
addLine(3, "if(installedChunks[chunkId]) callbacks.push.apply(callbacks, installedChunks[chunkId]);");
|
||||
addLine(3, "installedChunks[chunkId] = 0;");
|
||||
addLine(2, "}");
|
||||
addLine(2, "for(moduleId in moreModules)");
|
||||
addLine(3, "modules[moduleId] = moreModules[moduleId];");
|
||||
addLine(2, "while(callbacks.length)");
|
||||
addLine(3, "callbacks.shift().call(null, require);");
|
||||
addLine(1, "};");
|
||||
var jsonpFunction = this.outputOptions.jsonpFunction || ("webpackJsonp" + (this.outputOptions.library || ""));
|
||||
buf.push(
|
||||
"",
|
||||
"// install a JSONP callback for chunk loading",
|
||||
"window[" + JSON.stringify(jsonpFunction) + "] = function webpackJsonpCallback(chunkIds, moreModules) {",
|
||||
this.indent([
|
||||
'// add "moreModules" to the modules object,',
|
||||
'// then flag all "chunkIds" as loaded and fire callback',
|
||||
"var moduleId, chunkId, callbacks = [];",
|
||||
"while(chunkIds.length) {",
|
||||
this.indent([
|
||||
"chunkId = chunkIds.shift();",
|
||||
"if(installedChunks[chunkId])",
|
||||
this.indent("callbacks.push.apply(callbacks, installedChunks[chunkId]);"),
|
||||
"installedChunks[chunkId] = 0;"
|
||||
]),
|
||||
"}",
|
||||
"for(moduleId in moreModules)",
|
||||
this.indent("modules[moduleId] = moreModules[moduleId];"),
|
||||
"while(callbacks.length)",
|
||||
this.indent("callbacks.shift().call(null, require);"),
|
||||
]),
|
||||
"};"
|
||||
);
|
||||
}
|
||||
addLine(1, "return require(0);");
|
||||
addLine(0, "})({");
|
||||
addLine(0, "c: " + JSON.stringify(publicPath.replace(REGEXP_HASH, hash)) + ",");
|
||||
chunk.modules.forEach(function(module, idx) {
|
||||
if(idx != 0) buf.push(",\n");
|
||||
buf.push("\n/***/ " + module.id + ":\n");
|
||||
var source = moduleTemplate.render(module, dependencyTemplates);
|
||||
buf.push(source.source());
|
||||
});
|
||||
buf.push("\n");
|
||||
addLine(0, "})");
|
||||
return new StringSource(buf.join(""));
|
||||
return buf;
|
||||
};
|
||||
|
||||
JsonpMainTemplate.prototype.updateHash = function(hash) {
|
||||
MainTemplate.prototype.updateHash.call(this, hash);
|
||||
hash.update("jsonp");
|
||||
hash.update("2");
|
||||
hash.update(this.outputOptions.publicPath + "");
|
||||
hash.update("3");
|
||||
hash.update(this.outputOptions.filename + "");
|
||||
hash.update(this.outputOptions.chunkFilename + "");
|
||||
hash.update(this.outputOptions.jsonpFunction + "");
|
||||
hash.update(this.outputOptions.library + "");
|
||||
};
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
||||
var OriginalSource = require("webpack-core/lib/OriginalSource");
|
||||
var Template = require("./Template");
|
||||
|
||||
function MainTemplate(outputOptions) {
|
||||
Template.call(this, outputOptions);
|
||||
}
|
||||
module.exports = MainTemplate;
|
||||
|
||||
MainTemplate.prototype = Object.create(Template.prototype);
|
||||
MainTemplate.prototype.requireFn = "require";
|
||||
MainTemplate.prototype.render = function(hash, chunk, moduleTemplate, dependencyTemplates) {
|
||||
var buf = [];
|
||||
buf.push(this.asString(this.renderLocalVars(hash, chunk)));
|
||||
buf.push("");
|
||||
buf.push("// The require function");
|
||||
buf.push("function " + this.requireFn + "(moduleId) {");
|
||||
buf.push(this.indent(this.renderRequireContent(hash, chunk)));
|
||||
buf.push("}");
|
||||
buf.push("");
|
||||
buf.push(this.asString(this.renderRequireExtensions(hash, chunk)));
|
||||
buf.push(this.asString(this.renderInit(hash, chunk)));
|
||||
buf.push("");
|
||||
buf.push("// Load entry module and return exports");
|
||||
buf.push("return " + this.requireFn + "(0);");
|
||||
var bootstrapSource = new OriginalSource(buf.join("\n"), "webpackBootstrap " + hash);
|
||||
var source = new ConcatSource("(function(modules) { // webpackBootstrap\n", bootstrapSource, "\n})\n");
|
||||
source.add("/************************************************************************/\n");
|
||||
source.add("({\n");
|
||||
source.add(this.asString(this.renderInitModules(hash, chunk, moduleTemplate, dependencyTemplates)));
|
||||
chunk.modules.forEach(function(module, idx) {
|
||||
if(idx != 0) source.add(",\n");
|
||||
source.add("\n/***/ " + module.id + ":\n");
|
||||
source.add(moduleTemplate.render(module, dependencyTemplates));
|
||||
});
|
||||
source.add("\n})");
|
||||
return source;
|
||||
};
|
||||
|
||||
MainTemplate.prototype.indent = function indent(str) {
|
||||
if(Array.isArray(str)) {
|
||||
return str.map(indent).join("\n");
|
||||
} else {
|
||||
return "\t" + str.trimRight().replace(/\n/g, "\n\t");
|
||||
}
|
||||
};
|
||||
|
||||
MainTemplate.prototype.prefix = function(str, prefix) {
|
||||
if(Array.isArray(str)) {
|
||||
str = str.join("\n");
|
||||
}
|
||||
return prefix + str.trim().replace(/\n/g, "\n" + prefix);
|
||||
};
|
||||
|
||||
MainTemplate.prototype.asString = function(str) {
|
||||
if(Array.isArray(str)) {
|
||||
return str.join("\n");
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
MainTemplate.prototype.renderLocalVars = function(hash, chunk) {
|
||||
return [
|
||||
"// The module cache",
|
||||
"var installedModules = {};"
|
||||
];
|
||||
};
|
||||
|
||||
MainTemplate.prototype.renderRequireContent = function(hash, chunk) {
|
||||
return [
|
||||
"// Check if module is in cache",
|
||||
"if(installedModules[moduleId])",
|
||||
this.indent("return installedModules[moduleId].exports;"),
|
||||
"",
|
||||
"// Create a new module (and put it into the cache)",
|
||||
"var module = installedModules[moduleId] = {",
|
||||
this.indent([
|
||||
"exports: {},",
|
||||
"id: moduleId,",
|
||||
"loaded: false"
|
||||
]),
|
||||
"};",
|
||||
"",
|
||||
"// Execute the module function",
|
||||
"modules[moduleId].call(null, module, module.exports, " + this.requireFn + ");",
|
||||
"",
|
||||
"// Flag the module as loaded",
|
||||
"module.loaded = true;",
|
||||
"",
|
||||
"// Return the exports of the module",
|
||||
"return module.exports;",
|
||||
];
|
||||
};
|
||||
|
||||
MainTemplate.prototype.renderRequireExtensions = function(hash, chunk) {
|
||||
var buf = [];
|
||||
if(chunk.chunks.length == 0) {
|
||||
buf.push(this.requireFn + ".e = function requireEnsure(_, callback) {");
|
||||
buf.push(this.indent([
|
||||
"callback.call(null, require);"
|
||||
]));
|
||||
buf.push("};");
|
||||
} else {
|
||||
buf.push(this.requireFn + ".e = function requireEnsure(chunkId, callback) {");
|
||||
buf.push(this.indent(this.renderRequireEnsure(hash, chunk)));
|
||||
buf.push("};");
|
||||
}
|
||||
buf.push(this.requireFn + ".modules = modules;");
|
||||
buf.push(this.requireFn + ".cache = installedModules;");
|
||||
return buf;
|
||||
};
|
||||
|
||||
MainTemplate.prototype.renderInit = function(hash, chunk) {
|
||||
return [];
|
||||
};
|
||||
|
||||
MainTemplate.prototype.renderInitModules = function(hash, chunk, moduleTemplate, dependencyTemplates) {
|
||||
var publicPath = this.outputOptions.publicPath || "";
|
||||
return [
|
||||
"// __webpack_public_path__\n",
|
||||
"c: " + JSON.stringify(publicPath.replace(Template.REGEXP_HASH, hash)) + ","
|
||||
];
|
||||
};
|
||||
|
||||
MainTemplate.prototype.updateHash = function(hash) {
|
||||
hash.update("maintemplate");
|
||||
hash.update("1");
|
||||
hash.update(this.outputOptions.publicPath + "");
|
||||
};
|
|
@ -4,8 +4,10 @@
|
|||
*/
|
||||
var Module = require("./Module");
|
||||
var NormalModuleMixin = require("webpack-core/lib/NormalModuleMixin");
|
||||
var SourceMapSource = require("webpack-core/lib/SourceMapSource");
|
||||
var OriginalSource = require("webpack-core/lib/OriginalSource");
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var ReplaceSource = require("./ReplaceSource");
|
||||
var ReplaceSource = require("webpack-core/lib/ReplaceSource");
|
||||
var ModuleParseError = require("./ModuleParseError");
|
||||
var path = require("path");
|
||||
|
||||
|
@ -36,8 +38,14 @@ NormalModule.prototype.readableIdentifier = function(requestShortener) {
|
|||
NormalModule.prototype.fillLoaderContext = function fillLoaderContext(loaderContext, options, compilation) {
|
||||
loaderContext.webpack = true;
|
||||
compilation.applyPlugins("normal-module-loader", loaderContext);
|
||||
loaderContext.emitFile = function(name, content) {
|
||||
this.assets[name] = new RawSource(content);
|
||||
loaderContext.emitFile = function(name, content, sourceMap) {
|
||||
if(typeof sourceMap === "string") {
|
||||
this.assets[name] = new OriginalSource(content, sourceMap);
|
||||
} else if(sourceMap) {
|
||||
this.assets[name] = new SourceMapSource(content, name, sourceMap);
|
||||
} else {
|
||||
this.assets[name] = new RawSource(content);
|
||||
}
|
||||
}.bind(this);
|
||||
loaderContext.minimize = !!options.optimize.minimize;
|
||||
loaderContext._compilation = compilation;
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var Source = require("webpack-core/lib/Source");
|
||||
|
||||
function ReplaceSource(source) {
|
||||
Source.call(this);
|
||||
this._source = source;
|
||||
this.replacements = [];
|
||||
}
|
||||
module.exports = ReplaceSource;
|
||||
|
||||
ReplaceSource.prototype = Object.create(Source.prototype);
|
||||
|
||||
ReplaceSource.prototype.replace = function(start, end, newValue) {
|
||||
this.replacements.push([start, end, newValue]);
|
||||
};
|
||||
|
||||
ReplaceSource.prototype.insert = function(pos, newValue) {
|
||||
this.replacements.push([pos, pos-1, newValue]);
|
||||
};
|
||||
|
||||
ReplaceSource.prototype._bake = function() {
|
||||
this.replacements.sort(function(a, b) {
|
||||
return b[0] - a[0];
|
||||
});
|
||||
var result = [this._source.source()];
|
||||
this.replacements.forEach(function(repl) {
|
||||
var remSource = result.pop();
|
||||
result.push(
|
||||
remSource.substr(repl[1]+1),
|
||||
repl[2],
|
||||
remSource.substr(0, repl[0])
|
||||
);
|
||||
});
|
||||
result = result.reverse().join("");
|
||||
return {
|
||||
source: result
|
||||
}
|
||||
};
|
|
@ -2,8 +2,7 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var WrapSource = require("./WrapSource");
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
||||
|
||||
function SetVarMainTemplateDecorator(mainTemplate, varExpression) {
|
||||
this.mainTemplate = mainTemplate;
|
||||
|
@ -13,7 +12,7 @@ module.exports = SetVarMainTemplateDecorator;
|
|||
SetVarMainTemplateDecorator.prototype.render = function(hash, chunk, moduleTemplate, dependencyTemplates) {
|
||||
var source = this.mainTemplate.render(hash, chunk, moduleTemplate, dependencyTemplates);
|
||||
var prefix = this.varExpression + " =\n";
|
||||
return new WrapSource(new RawSource(prefix), source, new RawSource(""));
|
||||
return new ConcatSource(prefix, source);
|
||||
};
|
||||
SetVarMainTemplateDecorator.prototype.updateHash = function(hash) {
|
||||
hash.update("set var");
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var RequestShortener = require("./RequestShortener");
|
||||
var Template = require("./Template");
|
||||
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var base64Encode = require("base64-encode");
|
||||
|
||||
function SourceMapDevToolPlugin(context, sourceMapFilename) {
|
||||
this.context = context;
|
||||
this.sourceMapFilename = sourceMapFilename;
|
||||
}
|
||||
module.exports = SourceMapDevToolPlugin;
|
||||
SourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
||||
var sourceMapFilename = this.sourceMapFilename;
|
||||
var requestShortener = new RequestShortener(this.context);
|
||||
compiler.plugin("compilation", function(compilation) {
|
||||
compilation.plugin("after-optimize-chunk-assets", function(chunks) {
|
||||
chunks.forEach(function(chunk) {
|
||||
chunk.files.slice().forEach(function(file) {
|
||||
var asset = this.assets[file];
|
||||
var sourceMap = asset.map();
|
||||
if(sourceMap) {
|
||||
sourceMap.sources = sourceMap.sources.map(function(source) {
|
||||
var str;
|
||||
var module = compilation.findModule(source);
|
||||
if(module)
|
||||
str = module.readableIdentifier(requestShortener);
|
||||
else
|
||||
str = requestShortener.shorten(source);
|
||||
while(str.indexOf("?") >= 0 && str.indexOf("?") < str.lastIndexOf("!"))
|
||||
str = str.replace(/\?/, "(query)")
|
||||
return str;
|
||||
});
|
||||
sourceMap.sourceRoot = "webpack-module://";
|
||||
if(sourceMapFilename) {
|
||||
var sourceMapFile = sourceMapFilename
|
||||
.replace(Template.REGEXP_FILE, file)
|
||||
.replace(Template.REGEXP_FILEBASE, basename(file))
|
||||
.replace(Template.REGEXP_HASH, this.hash)
|
||||
.replace(Template.REGEXP_ID, chunk.id);
|
||||
this.assets[file] = new ConcatSource(asset, "\n/*\n//@ sourceMappingURL=" + basename(sourceMapFile) + "\n*/");
|
||||
this.assets[sourceMapFile] = new RawSource(JSON.stringify(sourceMap));
|
||||
chunk.files.push(sourceMapFile);
|
||||
} else {
|
||||
this.assets[file] = new ConcatSource(asset, "\n/*\n//@ sourceMappingURL=data:application/json;base64," + base64Encode(JSON.stringify(sourceMap)) + "\n*/");
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
}, this);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function basename(name) {
|
||||
if(name.indexOf("/") < 0) return name;
|
||||
return name.substr(name.lastIndexOf("/")+1);
|
||||
}
|
|
@ -71,6 +71,7 @@ Stats.prototype.toJson = function toJson(options, forToString) {
|
|||
return text;
|
||||
}
|
||||
var obj = {
|
||||
version: require("../package.json").version,
|
||||
errors: compilation.errors.map(formatError),
|
||||
warnings: compilation.warnings.map(formatError)
|
||||
};
|
||||
|
@ -264,6 +265,11 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
|
|||
bold(obj.hash);
|
||||
newline();
|
||||
}
|
||||
if(obj.version) {
|
||||
normal("Version: webpack ");
|
||||
bold(obj.version);
|
||||
newline();
|
||||
}
|
||||
if(obj.time) {
|
||||
normal("Time: ");
|
||||
bold(obj.time);
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
function Template(outputOptions) {
|
||||
this.outputOptions = outputOptions || {};
|
||||
}
|
||||
module.exports = Template;
|
||||
|
||||
Template.REGEXP_HASH = /\[hash\]/gi;
|
||||
Template.REGEXP_NAME = /\[name\]/gi;
|
||||
Template.REGEXP_ID = /\[id\]/gi;
|
||||
Template.REGEXP_FILE = /\[file\]/gi;
|
||||
Template.REGEXP_FILEBASE = /\[filebase\]/gi;
|
||||
|
||||
Template.prototype.indent = function indent(str) {
|
||||
if(Array.isArray(str)) {
|
||||
return str.map(indent).join("\n");
|
||||
} else {
|
||||
return "\t" + str.trimRight().replace(/\n/g, "\n\t");
|
||||
}
|
||||
};
|
||||
|
||||
Template.prototype.prefix = function(str, prefix) {
|
||||
if(Array.isArray(str)) {
|
||||
str = str.join("\n");
|
||||
}
|
||||
return prefix + str.trim().replace(/\n/g, "\n" + prefix);
|
||||
};
|
||||
|
||||
Template.prototype.asString = function(str) {
|
||||
if(Array.isArray(str)) {
|
||||
return str.join("\n");
|
||||
}
|
||||
return str;
|
||||
};
|
|
@ -2,8 +2,8 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var WrapSource = require("./WrapSource");
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
||||
var OriginalSource = require("webpack-core/lib/OriginalSource");
|
||||
|
||||
function UmdMainTemplateDecorator(mainTemplate, name) {
|
||||
this.mainTemplate = mainTemplate;
|
||||
|
@ -13,7 +13,7 @@ module.exports = UmdMainTemplateDecorator;
|
|||
UmdMainTemplateDecorator.prototype.render = function(hash, chunk, moduleTemplate, dependencyTemplates) {
|
||||
var source = this.mainTemplate.render(hash, chunk, moduleTemplate, dependencyTemplates);
|
||||
var prefix = "module.exports =\n";
|
||||
return new WrapSource(new RawSource(
|
||||
return new ConcatSource(new OriginalSource(
|
||||
"(function webpackUniversalModuleDefinition(root) {\n" +
|
||||
" return function webpackUniversalModuleDefinitionWrapBootstrap(fn) {\n" +
|
||||
" return function webpackUniversalModuleDefinitionBootstrap(modules) {\n" +
|
||||
|
@ -27,7 +27,7 @@ UmdMainTemplateDecorator.prototype.render = function(hash, chunk, moduleTemplate
|
|||
" root[" + JSON.stringify(this.name) + "] = fn(modules);\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"})(this)\n"), source, new RawSource(""));
|
||||
"})(this)\n", "webpackUniversalModuleDefinition"), source);
|
||||
};
|
||||
UmdMainTemplateDecorator.prototype.updateHash = function(hash) {
|
||||
hash.update("umd");
|
||||
|
|
|
@ -9,6 +9,7 @@ var JsonpTemplatePlugin = require("./JsonpTemplatePlugin");
|
|||
var WebWorkerTemplatePlugin = require("./webworker/WebWorkerTemplatePlugin");
|
||||
var NodeTemplatePlugin = require("./node/NodeTemplatePlugin");
|
||||
var EvalDevToolModulePlugin = require("./EvalDevToolModulePlugin");
|
||||
var SourceMapDevToolPlugin = require("./SourceMapDevToolPlugin");
|
||||
var LibraryTemplatePlugin = require("./LibraryTemplatePlugin");
|
||||
|
||||
var SingleEntryPlugin = require("./SingleEntryPlugin");
|
||||
|
@ -90,6 +91,12 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
|
|||
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")
|
||||
compiler.apply(new SourceMapDevToolPlugin(options.context, options.output.sourceMapFilename));
|
||||
else if(options.devtool == "inlinesourcemap" ||
|
||||
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);
|
||||
|
|
|
@ -19,6 +19,7 @@ function WebpackOptionsDefaulter() {
|
|||
|
||||
this.set("output.libraryTarget", "var");
|
||||
this.set("output.path", "");
|
||||
this.set("output.sourceMapFilename", "[file].map");
|
||||
|
||||
this.set("node.console", false);
|
||||
this.set("node.process", true);
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var Source = require("webpack-core/lib/Source");
|
||||
|
||||
function WrapSource(prefix, source, postfix) {
|
||||
Source.call(this);
|
||||
this.prefix = prefix;
|
||||
this._source = source;
|
||||
this.postfix = postfix;
|
||||
}
|
||||
module.exports = WrapSource;
|
||||
|
||||
WrapSource.prototype = Object.create(Source.prototype);
|
||||
|
||||
WrapSource.prototype._bake = function() {
|
||||
var prefix = this.prefix.source();
|
||||
var source = this._source.source();
|
||||
var postfix = this.postfix.source();
|
||||
return {
|
||||
source: prefix + source + postfix
|
||||
}
|
||||
};
|
|
@ -2,28 +2,25 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var ChunkTemplate = require("../ChunkTemplate");
|
||||
|
||||
function NodeChunkTemplate(outputOptions) {
|
||||
this.outputOptions = outputOptions || {};
|
||||
ChunkTemplate.call(this, outputOptions);
|
||||
}
|
||||
module.exports = NodeChunkTemplate;
|
||||
|
||||
NodeChunkTemplate.prototype.render = function(chunk, moduleTemplate, dependencyTemplates) {
|
||||
var buf = [];
|
||||
buf.push("exports.ids = " + JSON.stringify(chunk.ids) + ";\n");
|
||||
buf.push("exports.modules = {\n");
|
||||
chunk.modules.forEach(function(module, idx) {
|
||||
if(idx != 0) buf.push(",\n");
|
||||
buf.push("\n/***/ " + module.id + ":\n");
|
||||
var source = moduleTemplate.render(module, dependencyTemplates);
|
||||
buf.push(source.source());
|
||||
});
|
||||
buf.push("\n\n};");
|
||||
return new RawSource(buf.join(""));
|
||||
NodeChunkTemplate.prototype = Object.create(ChunkTemplate.prototype);
|
||||
NodeChunkTemplate.prototype.renderHeader = function(chunk) {
|
||||
var buf = ChunkTemplate.prototype.renderHeader.call(this, chunk);
|
||||
buf.unshift(
|
||||
"exports.ids = " + JSON.stringify(chunk.ids) + ";\n",
|
||||
"exports.modules = "
|
||||
);
|
||||
return buf;
|
||||
};
|
||||
|
||||
NodeChunkTemplate.prototype.updateHash = function(hash) {
|
||||
ChunkTemplate.prototype.updateHash.call(this, hash);
|
||||
hash.update("node");
|
||||
hash.update("2");
|
||||
hash.update("3");
|
||||
};
|
|
@ -2,81 +2,63 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var StringSource = require("webpack-core/lib/RawSource");
|
||||
var MainTemplate = require("../MainTemplate");
|
||||
var Template = require("../Template");
|
||||
|
||||
function NodeMainTemplate(outputOptions) {
|
||||
this.outputOptions = outputOptions || {};
|
||||
MainTemplate.call(this, outputOptions);
|
||||
}
|
||||
module.exports = NodeMainTemplate;
|
||||
|
||||
var REGEXP_HASH = /\[hash\]/i;
|
||||
var REGEXP_NAME = /\[name\]/g;
|
||||
var REGEXP_ID = /\[id\]/i;
|
||||
NodeMainTemplate.prototype.render = function(hash, chunk, moduleTemplate, dependencyTemplates) {
|
||||
NodeMainTemplate.prototype = Object.create(MainTemplate.prototype);
|
||||
|
||||
NodeMainTemplate.prototype.requireFn = "webpackRequire";
|
||||
NodeMainTemplate.prototype.renderLocalVars = function(hash, chunk) {
|
||||
var buf = MainTemplate.prototype.renderLocalVars.call(this, hash, chunk);
|
||||
if(chunk.chunks.length > 0) {
|
||||
buf.push(
|
||||
"",
|
||||
"// object to store loaded chunks",
|
||||
'// "1" means "already loaded"',
|
||||
"var installedChunks = {0:1};"
|
||||
);
|
||||
}
|
||||
return buf;
|
||||
};
|
||||
|
||||
NodeMainTemplate.prototype.renderRequireEnsure = function(hash, chunk) {
|
||||
var filename = this.outputOptions.filename || "bundle.js";
|
||||
var chunkFilename = this.outputOptions.chunkFilename || "[id]." + filename;
|
||||
var buf = [];
|
||||
function addLine(indent, line) {
|
||||
buf.push("/******/ ");
|
||||
for(var i = 0; i < indent; i++)
|
||||
buf.push("\t");
|
||||
buf.push(line);
|
||||
buf.push("\n");
|
||||
}
|
||||
function addRequireFunc(i) {
|
||||
addLine(i+0, "function __require(moduleId) {");
|
||||
addLine(i+1, "if(installedModules[moduleId])");
|
||||
addLine(i+2, "return installedModules[moduleId].exports;");
|
||||
addLine(i+1, "var module = installedModules[moduleId] = {");
|
||||
addLine(i+2, "exports: {},");
|
||||
addLine(i+2, "id: moduleId,");
|
||||
addLine(i+2, "loaded: false");
|
||||
addLine(i+1, "};");
|
||||
addLine(i+1, "modules[moduleId].call(null, module, module.exports, __require);");
|
||||
addLine(i+1, "module.loaded = true;");
|
||||
addLine(i+1, "return module.exports;");
|
||||
addLine(i+0, "}");
|
||||
}
|
||||
addLine(0, "(function webpackBootstrap(modules) {");
|
||||
addLine(1, "var installedModules = {};");
|
||||
addRequireFunc(1);
|
||||
addLine(1, "__require.e = function requireEnsure(chunkId, callback) {");
|
||||
if(chunk.chunks.length == 0) {
|
||||
addLine(2, "callback.call(null, __require);");
|
||||
} else {
|
||||
addLine(2, "if(installedChunks[chunkId] === 1) return callback.call(null, __require);");
|
||||
addLine(2, "var chunk = require(" + JSON.stringify("./" + chunkFilename.replace(REGEXP_HASH, hash).replace(REGEXP_NAME, "")).replace(REGEXP_ID, "\"+chunkId+\"") + ");");
|
||||
addLine(2, "var moreModules = chunk.modules, chunkIds = chunk.ids;");
|
||||
addLine(2, "for(var moduleId in moreModules)");
|
||||
addLine(3, "modules[moduleId] = moreModules[moduleId];");
|
||||
addLine(2, "for(var i = 0; i < chunkIds.length; i++)");
|
||||
addLine(3, "installedChunks[chunkIds[i]] = 1;");
|
||||
addLine(2, "callback.call(null, __require);");
|
||||
}
|
||||
addLine(1, "};");
|
||||
addLine(1, "__require.modules = modules;");
|
||||
addLine(1, "__require.cache = installedModules;");
|
||||
addLine(1, "__require.parentRequire = require;");
|
||||
if(chunk.chunks.length > 0) {
|
||||
addLine(1, "var installedChunks = {0:1};");
|
||||
}
|
||||
addLine(1, "return __require(0);");
|
||||
addLine(0, "})({");
|
||||
addLine(0, "c: __dirname,");
|
||||
chunk.modules.forEach(function(module, idx) {
|
||||
if(idx != 0) buf.push(",\n");
|
||||
buf.push("\n/***/ " + module.id + ":\n");
|
||||
var source = moduleTemplate.render(module, dependencyTemplates);
|
||||
buf.push(source.source());
|
||||
});
|
||||
buf.push("\n");
|
||||
addLine(0, "})");
|
||||
return new StringSource(buf.join(""));
|
||||
return [
|
||||
"// \"1\" is the signal for \"already loaded\"",
|
||||
"if(!installedChunks[chunkId]) {",
|
||||
this.indent([
|
||||
"var chunk = require(" +
|
||||
JSON.stringify("./" + chunkFilename
|
||||
.replace(Template.REGEXP_HASH, hash)
|
||||
.replace(Template.REGEXP_NAME, ""))
|
||||
.replace(Template.REGEXP_ID, "\" + chunkId + \"") + ");",
|
||||
"var moreModules = chunk.modules, chunkIds = chunk.ids;",
|
||||
"for(var moduleId in moreModules)",
|
||||
this.indent("modules[moduleId] = moreModules[moduleId];"),
|
||||
"for(var i = 0; i < chunkIds.length; i++)",
|
||||
this.indent("installedChunks[chunkIds[i]] = 1;"),
|
||||
]),
|
||||
"}",
|
||||
"callback.call(null, " + this.requireFn + ");",
|
||||
];
|
||||
};
|
||||
|
||||
NodeMainTemplate.prototype.renderRequireExtensions = function(hash, chunk) {
|
||||
var buf = MainTemplate.prototype.renderRequireExtensions.call(this, hash, chunk);
|
||||
buf.push(this.requireFn + ".parentRequire = require;");
|
||||
return buf;
|
||||
};
|
||||
|
||||
NodeMainTemplate.prototype.updateHash = function(hash) {
|
||||
MainTemplate.prototype.updateHash.call(this, hash);
|
||||
hash.update("node");
|
||||
hash.update("2");
|
||||
hash.update("3");
|
||||
hash.update(this.outputOptions.filename + "");
|
||||
hash.update(this.outputOptions.chunkFilename + "");
|
||||
};
|
|
@ -2,7 +2,7 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var SourceMapSource = require("webpack-core/lib/SourceMapSource");
|
||||
var uglify = require("uglify-js");
|
||||
|
||||
function UglifyJsPlugin(options) {
|
||||
|
@ -28,6 +28,7 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
|
|||
files.forEach(function(file) {
|
||||
try {
|
||||
var input = compilation.assets[file].source();
|
||||
var inputSourceMap = compilation.assets[file].map();
|
||||
var ast = uglify.parse(input, {
|
||||
filename: file
|
||||
});
|
||||
|
@ -39,11 +40,20 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
|
|||
ast.compute_char_frequency(options.mangle || {});
|
||||
ast.mangle_names(options.mangle || {});
|
||||
}
|
||||
var source = ast.print_to_string({
|
||||
comments: options.comments || /^\**!|@preserve|@license/,
|
||||
beautify: options.beautify
|
||||
var map = null;
|
||||
map = uglify.SourceMap({
|
||||
file: file,
|
||||
root: ""
|
||||
});
|
||||
compilation.assets[file] = new RawSource(source);
|
||||
var stream = uglify.OutputStream({
|
||||
comments: options.comments || /^\**!|@preserve|@license/,
|
||||
beautify: options.beautify,
|
||||
source_map: map
|
||||
});
|
||||
ast.print(stream);
|
||||
map = map + "";
|
||||
stream = stream + "";
|
||||
compilation.assets[file] = new SourceMapSource(stream, file, map, inputSourceMap);
|
||||
} catch(err) {
|
||||
err.file = file;
|
||||
compilation.warnings.push(err);
|
||||
|
|
|
@ -2,30 +2,31 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var ChunkTemplate = require("../ChunkTemplate");
|
||||
|
||||
function WebWorkerChunkTemplate(outputOptions) {
|
||||
this.outputOptions = outputOptions || {};
|
||||
ChunkTemplate.call(this, outputOptions);
|
||||
}
|
||||
module.exports = WebWorkerChunkTemplate;
|
||||
|
||||
WebWorkerChunkTemplate.prototype.render = function(chunk, moduleTemplate, dependencyTemplates) {
|
||||
WebWorkerChunkTemplate.prototype = Object.create(ChunkTemplate.prototype);
|
||||
WebWorkerChunkTemplate.prototype.renderHeader = function(chunk) {
|
||||
var buf = ChunkTemplate.prototype.renderHeader.call(this, chunk);
|
||||
var chunkCallbackName = this.outputOptions.chunkCallbackName || ("webpackChunk" + (this.outputOptions.library || ""));
|
||||
var buf = [];
|
||||
buf.push(chunkCallbackName + "(" + JSON.stringify(chunk.ids) + ", {\n");
|
||||
chunk.modules.forEach(function(module, idx) {
|
||||
if(idx != 0) buf.push(",\n");
|
||||
buf.push("\n/***/ " + module.id + ":\n");
|
||||
var source = moduleTemplate.render(module, dependencyTemplates);
|
||||
buf.push(source.source());
|
||||
});
|
||||
buf.push("\n\n})");
|
||||
return new RawSource(buf.join(""));
|
||||
buf.unshift(chunkCallbackName + "(" + JSON.stringify(chunk.ids) + ",");
|
||||
return buf;
|
||||
};
|
||||
|
||||
WebWorkerChunkTemplate.prototype.renderFooter = function(chunk) {
|
||||
var buf = ChunkTemplate.prototype.renderFooter.call(this, chunk);
|
||||
buf.push(")");
|
||||
return buf;
|
||||
};
|
||||
|
||||
WebWorkerChunkTemplate.prototype.updateHash = function(hash) {
|
||||
ChunkTemplate.prototype.updateHash.call(this, hash);
|
||||
hash.update("webworker");
|
||||
hash.update("2");
|
||||
hash.update("3");
|
||||
hash.update(this.outputOptions.chunkCallbackName + "");
|
||||
hash.update(this.outputOptions.library + "");
|
||||
};
|
|
@ -2,85 +2,72 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var StringSource = require("webpack-core/lib/RawSource");
|
||||
var MainTemplate = require("../MainTemplate");
|
||||
var Template = require("../Template");
|
||||
|
||||
function WebWorkerMainTemplate(outputOptions) {
|
||||
this.outputOptions = outputOptions || {};
|
||||
MainTemplate.call(this, outputOptions);
|
||||
}
|
||||
module.exports = WebWorkerMainTemplate;
|
||||
|
||||
var REGEXP_HASH = /\[hash\]/i;
|
||||
var REGEXP_NAME = /\[name\]/g;
|
||||
var REGEXP_ID = /\[id\]/i;
|
||||
WebWorkerMainTemplate.prototype.render = function(hash, chunk, moduleTemplate, dependencyTemplates) {
|
||||
var chunkCallbackName = this.outputOptions.chunkCallbackName || ("webpackChunk" + (this.outputOptions.library || ""));
|
||||
var publicPath = this.outputOptions.publicPath || "";
|
||||
WebWorkerMainTemplate.prototype = Object.create(MainTemplate.prototype);
|
||||
|
||||
WebWorkerMainTemplate.prototype.renderLocalVars = function(hash, chunk) {
|
||||
var buf = MainTemplate.prototype.renderLocalVars.call(this, hash, chunk);
|
||||
if(chunk.chunks.length > 0) {
|
||||
buf.push(
|
||||
"",
|
||||
"// object to store loaded chunks",
|
||||
'// "1" means "already loaded"',
|
||||
"var installedChunks = {0:1};"
|
||||
);
|
||||
}
|
||||
return buf;
|
||||
};
|
||||
|
||||
WebWorkerMainTemplate.prototype.renderRequireEnsure = function(hash, chunk) {
|
||||
var filename = this.outputOptions.filename || "bundle.js";
|
||||
var chunkFilename = this.outputOptions.chunkFilename || "[id]." + filename;
|
||||
var buf = [];
|
||||
function addLine(indent, line) {
|
||||
buf.push("/******/ ");
|
||||
for(var i = 0; i < indent; i++)
|
||||
buf.push("\t");
|
||||
buf.push(line);
|
||||
buf.push("\n");
|
||||
}
|
||||
function addRequireFunc(i) {
|
||||
addLine(i+0, "function require(moduleId) {");
|
||||
addLine(i+1, "if(installedModules[moduleId])");
|
||||
addLine(i+2, "return installedModules[moduleId].exports;");
|
||||
addLine(i+1, "var module = installedModules[moduleId] = {");
|
||||
addLine(i+2, "exports: {},");
|
||||
addLine(i+2, "id: moduleId,");
|
||||
addLine(i+2, "loaded: false");
|
||||
addLine(i+1, "};");
|
||||
addLine(i+1, "modules[moduleId].call(null, module, module.exports, require);");
|
||||
addLine(i+1, "module.loaded = true;");
|
||||
addLine(i+1, "return module.exports;");
|
||||
addLine(i+0, "}");
|
||||
}
|
||||
addLine(0, "(function webpackBootstrap(modules) {");
|
||||
addLine(1, "var installedModules = {};");
|
||||
addRequireFunc(1);
|
||||
addLine(1, "require.e = function requireEnsure(chunkId, callback) {");
|
||||
if(chunk.chunks.length == 0) {
|
||||
addLine(2, "callback.call(null, require);");
|
||||
} else {
|
||||
addLine(2, "if(installedChunks[chunkId] === 1) return callback.call(null, require);");
|
||||
addLine(2, "importScripts(" + JSON.stringify(chunkFilename.replace(REGEXP_HASH, hash).replace(REGEXP_NAME, "")).replace(REGEXP_ID, "\"+chunkId+\"") + ");");
|
||||
addLine(2, "callback.call(null, require);");
|
||||
}
|
||||
addLine(1, "};");
|
||||
addLine(1, "require.modules = modules;");
|
||||
addLine(1, "require.cache = installedModules;");
|
||||
return [
|
||||
"// \"1\" is the signal for \"already loaded\"",
|
||||
"if(!installedChunks[chunkId]) {",
|
||||
this.indent([
|
||||
"importScripts(" +
|
||||
JSON.stringify(chunkFilename
|
||||
.replace(Template.REGEXP_HASH, hash)
|
||||
.replace(Template.REGEXP_NAME, ""))
|
||||
.replace(Template.REGEXP_ID, "\" + chunkId + \"") + ");"
|
||||
]),
|
||||
"}",
|
||||
"callback.call(null, " + this.requireFn + ");"
|
||||
];
|
||||
};
|
||||
|
||||
WebWorkerMainTemplate.prototype.renderInit = function(hash, chunk) {
|
||||
var buf = MainTemplate.prototype.renderInit.call(this, hash, chunk);
|
||||
if(chunk.chunks.length > 0) {
|
||||
addLine(1, "var installedChunks = {0:1};");
|
||||
addLine(1, "this[" + JSON.stringify(chunkCallbackName) + "] = function webpackChunkCallback(chunkIds, moreModules) {");
|
||||
addLine(2, "for(var moduleId in moreModules)");
|
||||
addLine(3, "modules[moduleId] = moreModules[moduleId];");
|
||||
addLine(2, "for(var i = 0; i < chunkIds.length; i++)");
|
||||
addLine(3, "installedChunks[chunkIds[i]] = 1;");
|
||||
addLine(1, "};");
|
||||
var chunkCallbackName = this.outputOptions.chunkCallbackName || ("webpackChunk" + (this.outputOptions.library || ""));
|
||||
buf.push(
|
||||
"this[" + JSON.stringify(chunkCallbackName) + "] = function webpackChunkCallback(chunkIds, moreModules) {",
|
||||
this.indent([
|
||||
"for(var moduleId in moreModules)",
|
||||
this.indent("modules[moduleId] = moreModules[moduleId];"),
|
||||
"while(chunkIds.length)",
|
||||
this.indent("installedChunks[chunkIds.pop()] = 1;")
|
||||
]),
|
||||
"};"
|
||||
);
|
||||
}
|
||||
addLine(1, "return require(0);");
|
||||
addLine(0, "})({");
|
||||
addLine(0, "c: " + JSON.stringify(publicPath.replace(REGEXP_HASH, hash)) + ",");
|
||||
chunk.modules.forEach(function(module, idx) {
|
||||
if(idx != 0) buf.push(",\n");
|
||||
buf.push("\n/***/ " + module.id + ":\n");
|
||||
var source = moduleTemplate.render(module, dependencyTemplates);
|
||||
buf.push(source.source());
|
||||
});
|
||||
buf.push("\n");
|
||||
addLine(0, "})");
|
||||
return new StringSource(buf.join(""));
|
||||
return buf;
|
||||
};
|
||||
|
||||
WebWorkerMainTemplate.prototype.updateHash = function(hash) {
|
||||
MainTemplate.prototype.updateHash.call(this, hash);
|
||||
hash.update("webworker");
|
||||
hash.update("2");
|
||||
hash.update("3");
|
||||
hash.update(this.outputOptions.publicPath + "");
|
||||
hash.update(this.outputOptions.filename + "");
|
||||
hash.update(this.outputOptions.chunkFilename + "");
|
||||
hash.update(this.outputOptions.chunkCallbackName + "");
|
||||
hash.update(this.outputOptions.library + "");
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "webpack",
|
||||
"version": "0.9.3",
|
||||
"version": "0.10.0-beta1",
|
||||
"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": {
|
||||
|
@ -13,7 +13,8 @@
|
|||
"clone": "0.1.x",
|
||||
"webpack-core": "0.1.x",
|
||||
"node-libs-browser": "0.1.x",
|
||||
"tapable": "0.1.x"
|
||||
"tapable": "0.1.x",
|
||||
"base64-encode": "1.0.x"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@ library1.on("exit", function(code) {
|
|||
if(code === 0) {
|
||||
// node ../../bin/webpack --output-pathinfo --colors --resolve-alias vm=vm-browserify --output-public-path js/ --module-bind json --module-bind css=style!css --module-bind less=style!css!less --module-bind coffee --module-bind jade ./lib/index js/web.js
|
||||
var main = cp.spawn("node", join(["../../bin/webpack.js", "--output-pathinfo", "--colors", "--resolve-alias", "vm=vm-browserify", "--workers",
|
||||
"--output-public-path", "js/", "--module-bind", "json", "--module-bind", "css=style!css", "--module-bind", "less=style!css!less", "--module-bind", "coffee", "--module-bind", "jade", "./lib/index", "js/web.js", "--progress"], extraArgs));
|
||||
"--output-public-path", "js/", "--module-bind", "json", "--module-bind", "css=style!css", "--module-bind", "less=style/url!file?postfix=.css&string!less", "--module-bind", "coffee", "--module-bind", "jade", "./lib/index", "js/web.js", "--progress"], extraArgs));
|
||||
bindOutput(main);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -425,7 +425,7 @@ describe("main", function() {
|
|||
require("../../../package.json").name.should.be.eql("webpack");
|
||||
});
|
||||
it("should handle the jade loader correctly", function() {
|
||||
require("!jade!../resources/template.jade")({abc: "abc"}).should.be.eql("<p>abc</p>");
|
||||
require("!jade?self!../resources/template.jade")({abc: "abc"}).should.be.eql("<p>selfabc</p>");
|
||||
require("../resources/template.jade")({abc: "abc"}).should.be.eql("<p>abc</p>");
|
||||
});
|
||||
it("should handle the coffee loader correctly", function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
extends parent
|
||||
|
||||
block content
|
||||
= abc
|
||||
= typeof abc === "undefined" ? "self" + self.abc : abc
|
Loading…
Reference in New Issue