added alias, added support for http/vm-browserify
This commit is contained in:
parent
8a8c8b08ee
commit
f5651c8fa8
16
README.md
16
README.md
|
@ -173,13 +173,15 @@ if invoked without arguments it prints a usage:
|
|||
Usage: webpack <options> <input> <output>
|
||||
|
||||
Options:
|
||||
--single Disable Code Splitting [boolean] [default: false]
|
||||
--min Minimize it with uglifyjs [boolean] [default: false]
|
||||
--filenames Output Filenames Into File [boolean] [default: false]
|
||||
--options Options JSON File [string]
|
||||
--script-src-prefix Path Prefix For JavaScript Loading [string]
|
||||
--libary Stores the exports into this variable [string]
|
||||
--colors Output Stats with colors [boolean] [default: false]
|
||||
--single Disable Code Splitting [boolean] [default: false]
|
||||
--min Minimize it with uglifyjs [boolean] [default: false]
|
||||
--filenames Output Filenames Into File [boolean] [default: false]
|
||||
--options Options JSON File [string]
|
||||
--script-src-prefix Path Prefix For JavaScript Loading [string]
|
||||
--libary Stores the exports into this variable [string]
|
||||
--colors Output Stats with colors [boolean] [default: false]
|
||||
--json Output Stats as JSON [boolean] [default: false]
|
||||
--alias Set a alias name for a module. ex. http=http-browserify [string]
|
||||
```
|
||||
|
||||
### Programmatically Usage
|
||||
|
|
|
@ -39,6 +39,9 @@ var argv = require("optimist")
|
|||
.boolean("json")
|
||||
.describe("json", "Output Stats as JSON")
|
||||
.default("json", false)
|
||||
|
||||
.string("alias")
|
||||
.describe("alias", "Set a alias name for a module. ex. http=http-browserify")
|
||||
|
||||
.demand(1)
|
||||
.argv;
|
||||
|
@ -75,6 +78,18 @@ if(argv.libary) {
|
|||
options.libary = argv.libary;
|
||||
}
|
||||
|
||||
if(argv.alias) {
|
||||
if(typeof argv.alias === "string")
|
||||
argv.alias = [argv.alias];
|
||||
options.resolve = options.resolve || {};
|
||||
options.resolve.alias = options.resolve.alias || {};
|
||||
var aliasObj = options.resolve.alias;
|
||||
argv.alias.forEach(function(alias) {
|
||||
alias = alias.split("=");
|
||||
aliasObj[alias[0]] = alias[1];
|
||||
});
|
||||
}
|
||||
|
||||
var webpack = require("../lib/webpack.js");
|
||||
|
||||
if(argv.single) {
|
||||
|
|
|
@ -25,6 +25,8 @@ module.exports = function resolve(context, identifier, options, callback) {
|
|||
options.extensions = [".web.js", ".js"];
|
||||
if(!options.paths)
|
||||
options.paths = [];
|
||||
if(!options.alias)
|
||||
options.alias = {};
|
||||
function finalResult(err, absoluteFilename) {
|
||||
if(err) {
|
||||
callback("Module \"" + identifier + "\" not found in context \"" +
|
||||
|
@ -35,6 +37,13 @@ module.exports = function resolve(context, identifier, options, callback) {
|
|||
}
|
||||
var identArray = split(identifier);
|
||||
var contextArray = split(context);
|
||||
while(options.alias[identArray[0]]) {
|
||||
var old = identArray[0];
|
||||
identArray[0] = options.alias[identArray[0]];
|
||||
identArray = split(path.join.apply(path, identArray));
|
||||
if(identArray[0] === old)
|
||||
break;
|
||||
}
|
||||
if(identArray[0] === "." || identArray[0] === ".." || identArray[0] === "" || identArray[0].match(/^[A-Z]:$/i)) {
|
||||
var pathname = identArray[0][0] === "." ? join(contextArray, identArray) : path.join.apply(path, identArray);
|
||||
loadAsFile(pathname, options, function(err, absoluteFilename) {
|
||||
|
|
|
@ -36,6 +36,15 @@ var templateSingle = require("fs").readFileSync(path.join(__dirname, "templateSi
|
|||
minimize outputs with uglify-js
|
||||
- includeFilenames
|
||||
add absolute filenames of input files as comments
|
||||
- resolve.alias (object)
|
||||
replace a module. ex {"old-module": "new-module"}
|
||||
- resolve.extensions (object)
|
||||
possible extentions for files
|
||||
- resolve.paths (array)
|
||||
search paths
|
||||
- parse.overwrites (object)
|
||||
free module varables which are replaced with a module
|
||||
ex. { "$": "jquery" }
|
||||
*/
|
||||
module.exports = function(context, moduleName, options, callback) {
|
||||
if(typeof moduleName === "object") {
|
||||
|
@ -62,8 +71,12 @@ module.exports = function(context, moduleName, options, callback) {
|
|||
options.parse.overwrites.global = options.parse.overwrites.global || ("__webpack_global");
|
||||
options.resolve = options.resolve || {};
|
||||
options.resolve.paths = options.resolve.paths || [];
|
||||
options.resolve.paths.unshift(path.join(path.dirname(__dirname), "buildin"));
|
||||
options.resolve.paths.unshift(path.join(path.dirname(__dirname), "buildin", "web_modules"));
|
||||
options.resolve.paths.push(path.join(path.dirname(__dirname), "buildin"));
|
||||
options.resolve.paths.push(path.join(path.dirname(__dirname), "buildin", "web_modules"));
|
||||
options.resolve.paths.push(path.join(path.dirname(__dirname), "buildin", "node_modules"));
|
||||
options.resolve.alias = options.resolve.alias || {};
|
||||
options.resolve.alias.http = options.resolve.alias.http || path.join(path.dirname(__dirname), "node_modules", "http-browserify")
|
||||
options.resolve.alias.vm = options.resolve.alias.vm || path.join(path.dirname(__dirname), "node_modules", "vm-browserify")
|
||||
buildDeps(context, moduleName, options, function(err, depTree) {
|
||||
if(err) {
|
||||
callback(err);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "webpack",
|
||||
"version": "0.2.4",
|
||||
"version": "0.2.5",
|
||||
"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.",
|
||||
"dependencies": {
|
||||
|
@ -9,6 +9,10 @@
|
|||
"uglify-js": "1.2.5",
|
||||
"sprintf": "0.1.x"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"http-browserify": "*",
|
||||
"vm-browserify": "*"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
|
|
Loading…
Reference in New Issue