Shorten sourceURLs fixes #6
This commit is contained in:
parent
c95d4ca777
commit
514ad01e97
|
@ -361,6 +361,11 @@ You can also save this options object in a JSON file and use it with the shell c
|
|||
outputPostfix: ".chunk.js", // default: "." + output
|
||||
// postfix appended to id of lazy loaded chunks
|
||||
|
||||
context: "/home/node/stuff",
|
||||
// default: [context] parameter if Programmatically Usage
|
||||
// default: process.cwd() if Shell Usage
|
||||
// paths in stats and debug sourceUrl are shortened to this base directory
|
||||
|
||||
ouputJsonpFunction: "myJsonp", // default: "webpackJsonp"
|
||||
// jsonp function used for lazy loaded chunks,
|
||||
// should be unique for all instances of webpack in a page
|
||||
|
|
|
@ -156,6 +156,7 @@ if(!output) {
|
|||
if(!options.outputDirectory) options.outputDirectory = path.dirname(output);
|
||||
if(!options.output) options.output = path.basename(output);
|
||||
if(!options.outputPostfix) options.outputPostfix = "." + path.basename(output);
|
||||
if(!options.context) options.context = process.cwd();
|
||||
|
||||
// some listeners for the progress display
|
||||
if(argv.progress) {
|
||||
|
@ -213,7 +214,8 @@ if(!output) {
|
|||
console.log(formatOutput(stats, {
|
||||
colors: argv.colors,
|
||||
"by-size": argv["by-size"],
|
||||
verbose: argv.verbose
|
||||
verbose: argv.verbose,
|
||||
context: options.context
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var path = require("path");
|
||||
|
||||
module.exports = function(cwd) {
|
||||
var cwd = cwd;
|
||||
var cwdParent = path.dirname(cwd);
|
||||
var buildins = path.join(__dirname, "..");
|
||||
cwd = cwd.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
cwd = new RegExp("^" + cwd + "|(!)" + cwd, "g");
|
||||
var buildinsAsModule = cwd.test(buildins);
|
||||
cwdParent = cwdParent.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
cwdParent = new RegExp("^" + cwdParent + "|(!)" + cwdParent, "g");
|
||||
buildins = buildins.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
buildins = new RegExp("^" + buildins + "|(!)" + buildins, "g");
|
||||
var node_modulesRegExpA = /\/node_modules\//g;
|
||||
var node_modulesRegExpB = /\\node_modules\\/g;
|
||||
var index_jsRegExp = /[\\\/]index.js!/g;
|
||||
function compressFilename(filename) {
|
||||
if(!filename)
|
||||
return filename;
|
||||
if(buildinsAsModule)
|
||||
filename = filename.replace(buildins, "!(webpack)");
|
||||
filename = filename.replace(cwd, "!.");
|
||||
if(!buildinsAsModule)
|
||||
filename = filename.replace(buildins, "!(webpack)");
|
||||
filename = filename.replace(node_modulesRegExpA, "/~/");
|
||||
filename = filename.replace(node_modulesRegExpB, "\\~\\");
|
||||
filename = filename.replace(index_jsRegExp, "!");
|
||||
return filename.replace(/^!|!$/, "");
|
||||
}
|
||||
return compressFilename;
|
||||
}
|
|
@ -1,4 +1,9 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var sprintf = require("sprintf").sprintf;
|
||||
var createFilenameShortener = require("./createFilenameShortener");
|
||||
var path = require("path");
|
||||
module.exports = function(stats, options) {
|
||||
var buf = [];
|
||||
|
@ -18,32 +23,7 @@ module.exports = function(stats, options) {
|
|||
Object.keys(stats.fileSizes).forEach(function(file) {
|
||||
buf.push(c("\033[1m") + sprintf("%" + (3 + Object.keys(stats.fileSizes)[0].length) + "s", file) + c("\033[22m")+": "+c("\033[1m") + sprintf("%8d", stats.fileSizes[file]) + c("\033[22m") + " characters");
|
||||
});
|
||||
var cwd = process.cwd();
|
||||
var cwdParent = path.dirname(cwd);
|
||||
var buildins = path.join(__dirname, "..");
|
||||
cwd = cwd.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
cwd = new RegExp("^" + cwd + "|(!)" + cwd, "g");
|
||||
var buildinsAsModule = cwd.test(buildins);
|
||||
cwdParent = cwdParent.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
cwdParent = new RegExp("^" + cwdParent + "|(!)" + cwdParent, "g");
|
||||
buildins = buildins.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
buildins = new RegExp("^" + buildins + "|(!)" + buildins, "g");
|
||||
var node_modulesRegExpA = /\/node_modules\//g;
|
||||
var node_modulesRegExpB = /\\node_modules\\/g;
|
||||
var index_jsRegExp = /[\\\/]index.js!/g;
|
||||
function compressFilename(filename) {
|
||||
if(!filename)
|
||||
return filename;
|
||||
if(buildinsAsModule)
|
||||
filename = filename.replace(buildins, "!(webpack)");
|
||||
filename = filename.replace(cwd, "!.");
|
||||
if(!buildinsAsModule)
|
||||
filename = filename.replace(buildins, "!(webpack)");
|
||||
filename = filename.replace(node_modulesRegExpA, "/~/");
|
||||
filename = filename.replace(node_modulesRegExpB, "\\~\\");
|
||||
filename = filename.replace(index_jsRegExp, "!");
|
||||
return filename.replace(/^!|!$/, "");
|
||||
}
|
||||
var compressFilename = options.context ? createFilenameShortener(options.context) : function(f) { return f };
|
||||
if(stats.fileModules) {
|
||||
buf.push("");
|
||||
buf.push(" <id> <size> <filename>");
|
||||
|
|
|
@ -81,6 +81,8 @@ module.exports = function(context, moduleName, options, callback) {
|
|||
options.scriptSrcPrefix = options.scriptSrcPrefix || ""; // DEPRECATED
|
||||
options.publicPrefix = options.publicPrefix || options.scriptSrcPrefix
|
||||
|
||||
options.context = options.context || context;
|
||||
|
||||
if(options.output) {
|
||||
if(!options.outputDirectory) {
|
||||
options.outputDirectory = path.dirname(options.output);
|
||||
|
|
|
@ -205,6 +205,7 @@ module.exports = function(module, options, toRealId, toRealChuckId) {
|
|||
}
|
||||
if(options.debug) {
|
||||
// create a cool eval for debug mode
|
||||
var shortenFilename = require("./createFilenameShortener")(options.context);
|
||||
result = [
|
||||
"eval(",
|
||||
JSON.stringify([
|
||||
|
@ -213,7 +214,7 @@ module.exports = function(module, options, toRealId, toRealChuckId) {
|
|||
"// module.id = ", module.id, "\n",
|
||||
"// module.realId = ", module.realId, "\n",
|
||||
"// module.chunks = ", module.chunks.join(", "), "\n",
|
||||
"//@ sourceURL=webpack-module:///", encodeURI(module.filename || module.dirname).replace(/%5C|%2F/g, "/").replace(/^\//, "")
|
||||
"//@ sourceURL=webpack-module:///", encodeURI(shortenFilename(module.filename || module.dirname)).replace(/%5C|%2F/g, "/").replace(/^\//, "")
|
||||
].join("")),
|
||||
");"].join("");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "webpack",
|
||||
"version": "0.4.15",
|
||||
"version": "0.4.16",
|
||||
"author": "Tobias Koppers @sokra",
|
||||
"description": "Packs CommonJs Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loading of js, json, jade, coffee, css, ... out of the box and more with custom loaders.",
|
||||
"dependencies": {
|
||||
|
|
Loading…
Reference in New Issue