make it webpack-able
This commit is contained in:
parent
6c1e98f759
commit
58586f8ae2
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
(The MIT License)
|
(The MIT License)
|
||||||
|
|
||||||
Copyright (c) 2012 Tobias Koppers
|
Copyright (c) 2012 - 2013 Tobias Koppers
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
Author Tobias Koppers @sokra
|
Author Tobias Koppers @sokra
|
||||||
*/
|
*/
|
||||||
var ConstDependency = require("./dependencies/ConstDependency");
|
var ConstDependency = require("./dependencies/ConstDependency");
|
||||||
|
var BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
||||||
|
|
||||||
function APIPlugin() {
|
function APIPlugin() {
|
||||||
}
|
}
|
||||||
|
@ -14,6 +15,12 @@ var REPLACEMENTS = {
|
||||||
__webpack_modules__: "require.modules",
|
__webpack_modules__: "require.modules",
|
||||||
__webpack_chunk_load__: "require.e",
|
__webpack_chunk_load__: "require.e",
|
||||||
};
|
};
|
||||||
|
var REPLACEMENT_TYPES = {
|
||||||
|
__webpack_public_path__: "string",
|
||||||
|
__webpack_require__: "function",
|
||||||
|
__webpack_modules__: "object",
|
||||||
|
__webpack_chunk_load__: "function",
|
||||||
|
};
|
||||||
var IGNORES = [
|
var IGNORES = [
|
||||||
"call require.valueOf",
|
"call require.valueOf",
|
||||||
"expression require.onError",
|
"expression require.onError",
|
||||||
|
@ -26,6 +33,9 @@ APIPlugin.prototype.apply = function(compiler) {
|
||||||
this.state.current.addDependency(dep);
|
this.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
compiler.parser.plugin("evaluate typeof "+key, function(expr) {
|
||||||
|
return new BasicEvaluatedExpression().setString(REPLACEMENT_TYPES[key]).setRange(expr.range);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
IGNORES.forEach(function(key) {
|
IGNORES.forEach(function(key) {
|
||||||
compiler.parser.plugin(key, function(expr) {
|
compiler.parser.plugin(key, function(expr) {
|
||||||
|
|
|
@ -508,14 +508,14 @@ Compilation.prototype.createHash = function createHash() {
|
||||||
var hashFunction = outputOptions.hashFunction;
|
var hashFunction = outputOptions.hashFunction;
|
||||||
var hashDigest = outputOptions.hashDigest;
|
var hashDigest = outputOptions.hashDigest;
|
||||||
var hashDigestLength = outputOptions.hashDigestLength;
|
var hashDigestLength = outputOptions.hashDigestLength;
|
||||||
var hash = new (require("crypto").Hash)(hashFunction);
|
var hash = require("crypto").createHash(hashFunction);
|
||||||
this.mainTemplate.updateHash(hash);
|
this.mainTemplate.updateHash(hash);
|
||||||
this.chunkTemplate.updateHash(hash);
|
this.chunkTemplate.updateHash(hash);
|
||||||
this.moduleTemplate.updateHash(hash);
|
this.moduleTemplate.updateHash(hash);
|
||||||
var i, chunk;
|
var i, chunk;
|
||||||
for(i = 0; i < this.chunks.length; i++) {
|
for(i = 0; i < this.chunks.length; i++) {
|
||||||
var chunk = this.chunks[i];
|
var chunk = this.chunks[i];
|
||||||
var chunkHash = new (require("crypto").Hash)(hashFunction);
|
var chunkHash = require("crypto").createHash(hashFunction);
|
||||||
chunk.updateHash(chunkHash);
|
chunk.updateHash(chunkHash);
|
||||||
this.chunkTemplate.updateHash(chunkHash);
|
this.chunkTemplate.updateHash(chunkHash);
|
||||||
chunk.hash = chunkHash.digest(hashDigest);
|
chunk.hash = chunkHash.digest(hashDigest);
|
||||||
|
@ -531,7 +531,7 @@ Compilation.prototype.modifyHash = function modifyHash(update) {
|
||||||
var hashFunction = outputOptions.hashFunction;
|
var hashFunction = outputOptions.hashFunction;
|
||||||
var hashDigest = outputOptions.hashDigest;
|
var hashDigest = outputOptions.hashDigest;
|
||||||
var hashDigestLength = outputOptions.hashDigestLength;
|
var hashDigestLength = outputOptions.hashDigestLength;
|
||||||
var hash = new (require("crypto").Hash)(hashFunction);
|
var hash = require("crypto").createHash(hashFunction);
|
||||||
hash.update(this.fullHash);
|
hash.update(this.fullHash);
|
||||||
hash.update(update);
|
hash.update(update);
|
||||||
this.fullHash = hash.digest(hashDigest);
|
this.fullHash = hash.digest(hashDigest);
|
||||||
|
|
|
@ -36,7 +36,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
|
||||||
records.moduleHashs = {};
|
records.moduleHashs = {};
|
||||||
this.modules.forEach(function(module) {
|
this.modules.forEach(function(module) {
|
||||||
var identifier = module.identifier();
|
var identifier = module.identifier();
|
||||||
var hash = new (require("crypto")).Hash("md5");
|
var hash = require("crypto").createHash("md5");
|
||||||
module.updateHash(hash);
|
module.updateHash(hash);
|
||||||
records.moduleHashs[identifier] = hash.digest("hex");
|
records.moduleHashs[identifier] = hash.digest("hex");
|
||||||
});
|
});
|
||||||
|
@ -70,7 +70,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
|
||||||
var moduleHashs = {};
|
var moduleHashs = {};
|
||||||
this.modules.forEach(function(module) {
|
this.modules.forEach(function(module) {
|
||||||
var identifier = module.identifier();
|
var identifier = module.identifier();
|
||||||
var hash = new (require("crypto")).Hash("md5");
|
var hash = require("crypto").createHash("md5");
|
||||||
module.updateHash(hash);
|
module.updateHash(hash);
|
||||||
hash = hash.digest("hex");
|
hash = hash.digest("hex");
|
||||||
module.hotUpdate = records.moduleHashs[identifier] !== hash;
|
module.hotUpdate = records.moduleHashs[identifier] !== hash;
|
||||||
|
|
|
@ -157,7 +157,7 @@ NormalModule.prototype.updateHash = function(hash) {
|
||||||
|
|
||||||
NormalModule.prototype.getSourceHash = function() {
|
NormalModule.prototype.getSourceHash = function() {
|
||||||
if(!this._source) return "";
|
if(!this._source) return "";
|
||||||
var hash = new (require("crypto").Hash)("md5");
|
var hash = require("crypto").createHash("md5");
|
||||||
hash.update(this._source.source());
|
hash.update(this._source.source());
|
||||||
return hash.digest("hex");
|
return hash.digest("hex");
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,19 +6,32 @@ var path = require("path");
|
||||||
|
|
||||||
function RequestShortener(directory) {
|
function RequestShortener(directory) {
|
||||||
var parentDirectory = path.dirname(directory);
|
var parentDirectory = path.dirname(directory);
|
||||||
var buildins = path.join(__dirname, "..");
|
if(/[\/\\]$/.test(directory)) directory = directory.substr(0, directory.length - 1);
|
||||||
var currentDirectoryRegExp = directory.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
if(directory) {
|
||||||
currentDirectoryRegExp = new RegExp("^" + currentDirectoryRegExp + "|(!)" + currentDirectoryRegExp, "g");
|
var currentDirectoryRegExp = directory.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||||
var buildinsAsModule = currentDirectoryRegExp.test(buildins);
|
currentDirectoryRegExp = new RegExp("^" + currentDirectoryRegExp + "|(!)" + currentDirectoryRegExp, "g");
|
||||||
var parentDirectoryRegExp = parentDirectory.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
||||||
parentDirectoryRegExp = new RegExp("^" + parentDirectoryRegExp + "|(!)" + parentDirectoryRegExp, "g");
|
this.currentDirectoryRegExp = currentDirectoryRegExp;
|
||||||
var buildinsRegExp = buildins.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
}
|
||||||
buildinsRegExp = new RegExp("^" + buildinsRegExp + "|(!)" + buildinsRegExp, "g");
|
|
||||||
|
if(/[\/\\]$/.test(parentDirectory)) parentDirectory = parentDirectory.substr(0, parentDirectory.length - 1);
|
||||||
|
if(parentDirectory && parentDirectory !== directory) {
|
||||||
|
var parentDirectoryRegExp = parentDirectory.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||||
|
parentDirectoryRegExp = new RegExp("^" + parentDirectoryRegExp + "|(!)" + parentDirectoryRegExp, "g");
|
||||||
|
|
||||||
|
this.parentDirectoryRegExp = parentDirectoryRegExp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(__dirname.length >= 2) {
|
||||||
|
var buildins = path.join(__dirname, "..");
|
||||||
|
var buildinsAsModule = currentDirectoryRegExp.test(buildins);
|
||||||
|
var buildinsRegExp = buildins.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||||
|
buildinsRegExp = new RegExp("^" + buildinsRegExp + "|(!)" + buildinsRegExp, "g");
|
||||||
|
|
||||||
|
this.buildinsAsModule = buildinsAsModule;
|
||||||
|
this.buildinsRegExp = buildinsRegExp;
|
||||||
|
}
|
||||||
|
|
||||||
this.buildinsAsModule = buildinsAsModule;
|
|
||||||
this.currentDirectoryRegExp = currentDirectoryRegExp;
|
|
||||||
this.parentDirectoryRegExp = parentDirectoryRegExp;
|
|
||||||
this.buildinsRegExp = buildinsRegExp;
|
|
||||||
this.node_modulesRegExp = /\/node_modules\//g;
|
this.node_modulesRegExp = /\/node_modules\//g;
|
||||||
this.index_jsRegExp = /\/index.js(!|\?|\(query\))/g;
|
this.index_jsRegExp = /\/index.js(!|\?|\(query\))/g;
|
||||||
}
|
}
|
||||||
|
@ -27,11 +40,13 @@ module.exports = RequestShortener;
|
||||||
RequestShortener.prototype.shorten = function(request) {
|
RequestShortener.prototype.shorten = function(request) {
|
||||||
if(!request)
|
if(!request)
|
||||||
return request;
|
return request;
|
||||||
if(this.buildinsAsModule)
|
if(this.buildinsAsModule && this.buildinsRegExp)
|
||||||
request = request.replace(this.buildinsRegExp, "!(webpack)");
|
request = request.replace(this.buildinsRegExp, "!(webpack)");
|
||||||
request = request.replace(this.currentDirectoryRegExp, "!.");
|
if(this.currentDirectoryRegExp)
|
||||||
request = request.replace(this.parentDirectoryRegExp, "!..");
|
request = request.replace(this.currentDirectoryRegExp, "!.");
|
||||||
if(!this.buildinsAsModule)
|
if(this.parentDirectoryRegExp)
|
||||||
|
request = request.replace(this.parentDirectoryRegExp, "!..");
|
||||||
|
if(!this.buildinsAsModule && this.buildinsRegExp)
|
||||||
request = request.replace(this.buildinsRegExp, "!(webpack)");
|
request = request.replace(this.buildinsRegExp, "!(webpack)");
|
||||||
request = request.replace(/\\/g, "/");
|
request = request.replace(/\\/g, "/");
|
||||||
request = request.replace(this.node_modulesRegExp, "/~/");
|
request = request.replace(this.node_modulesRegExp, "/~/");
|
||||||
|
|
|
@ -191,6 +191,7 @@ Stats.prototype.toJson = function toJson(options, forToString) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Stats.prototype.toString = function toString(options) {
|
Stats.prototype.toString = function toString(options) {
|
||||||
|
if(!options) options = {};
|
||||||
function d(v, d) { return v === undefined ? d : v }
|
function d(v, d) { return v === undefined ? d : v }
|
||||||
var useColors = d(options.colors, false);
|
var useColors = d(options.colors, false);
|
||||||
|
|
||||||
|
|
|
@ -5,19 +5,11 @@
|
||||||
var OptionsApply = require("./OptionsApply");
|
var OptionsApply = require("./OptionsApply");
|
||||||
|
|
||||||
var FunctionModulePlugin = require("./FunctionModulePlugin");
|
var FunctionModulePlugin = require("./FunctionModulePlugin");
|
||||||
var JsonpTemplatePlugin = require("./JsonpTemplatePlugin");
|
|
||||||
var WebWorkerTemplatePlugin = require("./webworker/WebWorkerTemplatePlugin");
|
|
||||||
var NodeTemplatePlugin = require("./node/NodeTemplatePlugin");
|
|
||||||
var EvalDevToolModulePlugin = require("./EvalDevToolModulePlugin");
|
var EvalDevToolModulePlugin = require("./EvalDevToolModulePlugin");
|
||||||
var SourceMapDevToolPlugin = require("./SourceMapDevToolPlugin");
|
var SourceMapDevToolPlugin = require("./SourceMapDevToolPlugin");
|
||||||
var LibraryTemplatePlugin = require("./LibraryTemplatePlugin");
|
|
||||||
var HotModuleReplacementPlugin = require("./HotModuleReplacementPlugin");
|
|
||||||
var NoHotModuleReplacementPlugin = require("./NoHotModuleReplacementPlugin");
|
|
||||||
|
|
||||||
var PrefetchPlugin = require("./PrefetchPlugin");
|
|
||||||
var SingleEntryPlugin = require("./SingleEntryPlugin");
|
var SingleEntryPlugin = require("./SingleEntryPlugin");
|
||||||
var MultiEntryPlugin = require("./MultiEntryPlugin");
|
var MultiEntryPlugin = require("./MultiEntryPlugin");
|
||||||
var CachePlugin = require("./CachePlugin");
|
|
||||||
var RecordIdsPlugin = require("./RecordIdsPlugin");
|
var RecordIdsPlugin = require("./RecordIdsPlugin");
|
||||||
|
|
||||||
var APIPlugin = require("./APIPlugin");
|
var APIPlugin = require("./APIPlugin");
|
||||||
|
@ -25,9 +17,6 @@ var ConstPlugin = require("./ConstPlugin");
|
||||||
var RequireJsStuffPlugin = require("./RequireJsStuffPlugin");
|
var RequireJsStuffPlugin = require("./RequireJsStuffPlugin");
|
||||||
var NodeStuffPlugin = require("./NodeStuffPlugin");
|
var NodeStuffPlugin = require("./NodeStuffPlugin");
|
||||||
var CompatibilityPlugin = require("./CompatibilityPlugin");
|
var CompatibilityPlugin = require("./CompatibilityPlugin");
|
||||||
var ProvidePlugin = require("./ProvidePlugin");
|
|
||||||
var NodeSourcePlugin = require("./node/NodeSourcePlugin");
|
|
||||||
var NodeTargetPlugin = require("./node/NodeTargetPlugin");
|
|
||||||
|
|
||||||
var CommonJsPlugin = require("./dependencies/CommonJsPlugin");
|
var CommonJsPlugin = require("./dependencies/CommonJsPlugin");
|
||||||
var AMDPlugin = require("./dependencies/AMDPlugin");
|
var AMDPlugin = require("./dependencies/AMDPlugin");
|
||||||
|
@ -36,15 +25,10 @@ var RequireContextPlugin = require("./dependencies/RequireContextPlugin");
|
||||||
var RequireEnsurePlugin = require("./dependencies/RequireEnsurePlugin");
|
var RequireEnsurePlugin = require("./dependencies/RequireEnsurePlugin");
|
||||||
var RequireIncludePlugin = require("./dependencies/RequireIncludePlugin");
|
var RequireIncludePlugin = require("./dependencies/RequireIncludePlugin");
|
||||||
|
|
||||||
var UglifyJsPlugin = require("./optimize/UglifyJsPlugin");
|
|
||||||
var OccurenceOrderPlugin = require("./optimize/OccurenceOrderPlugin");
|
|
||||||
var LimitChunkCountPlugin = require("./optimize/LimitChunkCountPlugin");
|
|
||||||
var MinChunkSizePlugin = require("./optimize/MinChunkSizePlugin");
|
|
||||||
var RemoveParentModulesPlugin = require("./optimize/RemoveParentModulesPlugin");
|
var RemoveParentModulesPlugin = require("./optimize/RemoveParentModulesPlugin");
|
||||||
var RemoveEmptyChunksPlugin = require("./optimize/RemoveEmptyChunksPlugin");
|
var RemoveEmptyChunksPlugin = require("./optimize/RemoveEmptyChunksPlugin");
|
||||||
var MergeDuplicateChunksPlugin = require("./optimize/MergeDuplicateChunksPlugin");
|
var MergeDuplicateChunksPlugin = require("./optimize/MergeDuplicateChunksPlugin");
|
||||||
var FlagIncludedChunksPlugin = require("./optimize/FlagIncludedChunksPlugin");
|
var FlagIncludedChunksPlugin = require("./optimize/FlagIncludedChunksPlugin");
|
||||||
var DedupePlugin = require("./optimize/DedupePlugin");
|
|
||||||
|
|
||||||
var UnsafeCachePlugin = require("enhanced-resolve/lib/UnsafeCachePlugin");
|
var UnsafeCachePlugin = require("enhanced-resolve/lib/UnsafeCachePlugin");
|
||||||
var ModulesInDirectoriesPlugin = require("enhanced-resolve/lib/ModulesInDirectoriesPlugin");
|
var ModulesInDirectoriesPlugin = require("enhanced-resolve/lib/ModulesInDirectoriesPlugin");
|
||||||
|
@ -74,6 +58,8 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
|
||||||
compiler.recordsOutputPath = options.recordsOutputPath || options.recordsPath;
|
compiler.recordsOutputPath = options.recordsOutputPath || options.recordsPath;
|
||||||
switch(options.target) {
|
switch(options.target) {
|
||||||
case "web":
|
case "web":
|
||||||
|
var JsonpTemplatePlugin = require("./JsonpTemplatePlugin");
|
||||||
|
var NodeSourcePlugin = require("./node/NodeSourcePlugin");
|
||||||
compiler.apply(
|
compiler.apply(
|
||||||
new JsonpTemplatePlugin(options.output),
|
new JsonpTemplatePlugin(options.output),
|
||||||
new FunctionModulePlugin(options.context, options.output),
|
new FunctionModulePlugin(options.context, options.output),
|
||||||
|
@ -81,6 +67,8 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "webworker":
|
case "webworker":
|
||||||
|
var WebWorkerTemplatePlugin = require("./webworker/WebWorkerTemplatePlugin");
|
||||||
|
var NodeSourcePlugin = require("./node/NodeSourcePlugin");
|
||||||
compiler.apply(
|
compiler.apply(
|
||||||
new WebWorkerTemplatePlugin(options.output),
|
new WebWorkerTemplatePlugin(options.output),
|
||||||
new FunctionModulePlugin(options.context, options.output),
|
new FunctionModulePlugin(options.context, options.output),
|
||||||
|
@ -88,6 +76,8 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "node":
|
case "node":
|
||||||
|
var NodeTemplatePlugin = require("./node/NodeTemplatePlugin");
|
||||||
|
var NodeTargetPlugin = require("./node/NodeTargetPlugin");
|
||||||
compiler.apply(
|
compiler.apply(
|
||||||
new NodeTemplatePlugin(options.output),
|
new NodeTemplatePlugin(options.output),
|
||||||
new FunctionModulePlugin(options.context, options.output),
|
new FunctionModulePlugin(options.context, options.output),
|
||||||
|
@ -96,12 +86,15 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(options.output.library || options.output.libraryTarget != "var") {
|
if(options.output.library || options.output.libraryTarget != "var") {
|
||||||
|
var LibraryTemplatePlugin = require("./LibraryTemplatePlugin");
|
||||||
compiler.apply(new LibraryTemplatePlugin(options.output.library, options.output.libraryTarget));
|
compiler.apply(new LibraryTemplatePlugin(options.output.library, options.output.libraryTarget));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(options.hot) {
|
if(options.hot) {
|
||||||
|
var HotModuleReplacementPlugin = require("./HotModuleReplacementPlugin");
|
||||||
compiler.apply(new HotModuleReplacementPlugin(options.output));
|
compiler.apply(new HotModuleReplacementPlugin(options.output));
|
||||||
} else {
|
} else {
|
||||||
|
var NoHotModuleReplacementPlugin = require("./NoHotModuleReplacementPlugin");
|
||||||
compiler.apply(new NoHotModuleReplacementPlugin());
|
compiler.apply(new NoHotModuleReplacementPlugin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +146,7 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(options.prefetch) {
|
if(options.prefetch) {
|
||||||
|
var PrefetchPlugin = require("./PrefetchPlugin");
|
||||||
options.prefetch.map(function(request) {
|
options.prefetch.map(function(request) {
|
||||||
compiler.apply(new PrefetchPlugin(options.context, request));
|
compiler.apply(new PrefetchPlugin(options.context, request));
|
||||||
});
|
});
|
||||||
|
@ -180,27 +174,41 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
|
||||||
|
|
||||||
compiler.apply(new RecordIdsPlugin());
|
compiler.apply(new RecordIdsPlugin());
|
||||||
|
|
||||||
if(options.optimize && options.optimize.occurenceOrder)
|
if(options.optimize && options.optimize.occurenceOrder) {
|
||||||
|
var OccurenceOrderPlugin = require("./optimize/OccurenceOrderPlugin");
|
||||||
compiler.apply(new OccurenceOrderPlugin(options.optimize.occurenceOrderPreferEntry));
|
compiler.apply(new OccurenceOrderPlugin(options.optimize.occurenceOrderPreferEntry));
|
||||||
|
}
|
||||||
|
|
||||||
if(options.optimize && options.optimize.minChunkSize)
|
if(options.optimize && options.optimize.minChunkSize) {
|
||||||
|
var MinChunkSizePlugin = require("./optimize/MinChunkSizePlugin");
|
||||||
compiler.apply(new MinChunkSizePlugin(options.optimize));
|
compiler.apply(new MinChunkSizePlugin(options.optimize));
|
||||||
|
}
|
||||||
|
|
||||||
if(options.optimize && options.optimize.maxChunks)
|
if(options.optimize && options.optimize.maxChunks) {
|
||||||
|
var LimitChunkCountPlugin = require("./optimize/LimitChunkCountPlugin");
|
||||||
compiler.apply(new LimitChunkCountPlugin(options.optimize));
|
compiler.apply(new LimitChunkCountPlugin(options.optimize));
|
||||||
|
}
|
||||||
|
|
||||||
if(options.optimize.minimize === true)
|
if(options.optimize.minimize) {
|
||||||
compiler.apply(new UglifyJsPlugin());
|
var UglifyJsPlugin = require("./optimize/UglifyJsPlugin");
|
||||||
else if(options.optimize.minimize)
|
if(options.optimize.minimize === true)
|
||||||
compiler.apply(new UglifyJsPlugin(options.optimize.minimize));
|
compiler.apply(new UglifyJsPlugin());
|
||||||
|
else
|
||||||
|
compiler.apply(new UglifyJsPlugin(options.optimize.minimize));
|
||||||
|
}
|
||||||
|
|
||||||
if(options.optimize.dedupe === true)
|
if(options.optimize.dedupe === true) {
|
||||||
|
var DedupePlugin = require("./optimize/DedupePlugin");
|
||||||
compiler.apply(new DedupePlugin());
|
compiler.apply(new DedupePlugin());
|
||||||
|
}
|
||||||
|
|
||||||
if(options.cache === undefined ? options.watch : options.cache)
|
if(options.cache === undefined ? options.watch : options.cache) {
|
||||||
|
var CachePlugin = require("./CachePlugin");
|
||||||
compiler.apply(new CachePlugin(typeof options.cache == "object" ? options.cache : null));
|
compiler.apply(new CachePlugin(typeof options.cache == "object" ? options.cache : null));
|
||||||
|
}
|
||||||
|
|
||||||
if(typeof options.provide === "object") {
|
if(typeof options.provide === "object") {
|
||||||
|
var ProvidePlugin = require("./ProvidePlugin");
|
||||||
for(var name in options.provide) {
|
for(var name in options.provide) {
|
||||||
compiler.apply(new ProvidePlugin(name, options.provide[name]));
|
compiler.apply(new ProvidePlugin(name, options.provide[name]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,10 @@ module.exports = AbstractPlugin.create({
|
||||||
switch(expr.arguments.length) {
|
switch(expr.arguments.length) {
|
||||||
case 1:
|
case 1:
|
||||||
if(expr.arguments[0].type == "FunctionExpression") {
|
if(expr.arguments[0].type == "FunctionExpression") {
|
||||||
|
// define(f() {...})
|
||||||
fn = expr.arguments[0];
|
fn = expr.arguments[0];
|
||||||
} else {
|
} else {
|
||||||
|
// define({...})
|
||||||
var dep = new AMDDefineDependency(expr.range, expr.arguments[0].range);
|
var dep = new AMDDefineDependency(expr.range, expr.arguments[0].range);
|
||||||
dep.loc = expr.loc;
|
dep.loc = expr.loc;
|
||||||
this.state.current.addDependency(dep);
|
this.state.current.addDependency(dep);
|
||||||
|
@ -24,14 +26,18 @@ module.exports = AbstractPlugin.create({
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if(expr.arguments[0].type == "ArrayExpression" && expr.arguments[1].type == "FunctionExpression") {
|
if(expr.arguments[0].type == "ArrayExpression") {
|
||||||
|
// define([...], f() {...})
|
||||||
array = expr.arguments[0];
|
array = expr.arguments[0];
|
||||||
fn = expr.arguments[1];
|
fn = expr.arguments[1];
|
||||||
} else if(expr.arguments[0].type == "Literal" && expr.arguments[1].type == "FunctionExpression") {
|
|
||||||
fn = expr.arguments[1];
|
|
||||||
} else if(expr.arguments[0].type == "Literal" && expr.arguments[1].type == "ArrayExpression") {
|
} else if(expr.arguments[0].type == "Literal" && expr.arguments[1].type == "ArrayExpression") {
|
||||||
|
// define("...", [...])
|
||||||
array = expr.arguments[1];
|
array = expr.arguments[1];
|
||||||
|
} else if(expr.arguments[0].type == "Literal" && expr.arguments[1].type == "FunctionExpression") {
|
||||||
|
// define("...", f() {...})
|
||||||
|
fn = expr.arguments[1];
|
||||||
} else if(expr.arguments[0].type == "Literal") {
|
} else if(expr.arguments[0].type == "Literal") {
|
||||||
|
// define("...", {...})
|
||||||
var dep = new AMDDefineDependency(expr.range, expr.arguments[1].range);
|
var dep = new AMDDefineDependency(expr.range, expr.arguments[1].range);
|
||||||
dep.loc = expr.loc;
|
dep.loc = expr.loc;
|
||||||
this.state.current.addDependency(dep);
|
this.state.current.addDependency(dep);
|
||||||
|
@ -40,8 +46,8 @@ module.exports = AbstractPlugin.create({
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if(expr.arguments[0].type == "Literal" &&
|
if(expr.arguments[0].type == "Literal" &&
|
||||||
expr.arguments[1].type == "ArrayExpression" &&
|
expr.arguments[1].type == "ArrayExpression") {
|
||||||
expr.arguments[2].type == "FunctionExpression") {
|
// define("...", [...], f() {...})
|
||||||
array = expr.arguments[1];
|
array = expr.arguments[1];
|
||||||
fn = expr.arguments[2];
|
fn = expr.arguments[2];
|
||||||
}
|
}
|
||||||
|
@ -57,7 +63,7 @@ module.exports = AbstractPlugin.create({
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
if(fn) {
|
if(fn && fn.type === "FunctionExpression") {
|
||||||
var inTry = this.scope.inTry;
|
var inTry = this.scope.inTry;
|
||||||
this.inScope(fn.params.filter(function(i) {
|
this.inScope(fn.params.filter(function(i) {
|
||||||
return ["require", "module", "exports"].indexOf(i.name) < 0;
|
return ["require", "module", "exports"].indexOf(i.name) < 0;
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||||
|
Author Tobias Koppers @sokra
|
||||||
|
*/
|
||||||
|
function WebEnvironmentPlugin(inputFileSystem, outputFileSystem) {
|
||||||
|
this.inputFileSystem = inputFileSystem;
|
||||||
|
this.outputFileSystem = outputFileSystem;
|
||||||
|
}
|
||||||
|
module.exports = WebEnvironmentPlugin;
|
||||||
|
WebEnvironmentPlugin.prototype.apply = function(compiler) {
|
||||||
|
var inputFileSystem = compiler.inputFileSystem = this.inputFileSystem;
|
||||||
|
compiler.resolvers.normal.fileSystem = compiler.inputFileSystem;
|
||||||
|
compiler.resolvers.context.fileSystem = compiler.inputFileSystem;
|
||||||
|
compiler.resolvers.loader.fileSystem = compiler.inputFileSystem;
|
||||||
|
compiler.outputFileSystem = this.outputFileSystem;
|
||||||
|
};
|
|
@ -13,7 +13,7 @@ function webpack(options, callback) {
|
||||||
var compiler = new Compiler();
|
var compiler = new Compiler();
|
||||||
compiler.options = options;
|
compiler.options = options;
|
||||||
compiler.options = new WebpackOptionsApply().process(options, compiler);
|
compiler.options = new WebpackOptionsApply().process(options, compiler);
|
||||||
new NodeEnvironmentPlugin(options.separate).apply(compiler);
|
new NodeEnvironmentPlugin().apply(compiler);
|
||||||
if(callback) {
|
if(callback) {
|
||||||
if(options.watch) {
|
if(options.watch) {
|
||||||
return compiler.watch(options.watchDelay, callback);
|
return compiler.watch(options.watchDelay, callback);
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||||
|
Author Tobias Koppers @sokra
|
||||||
|
*/
|
||||||
|
var Compiler = require("./Compiler");
|
||||||
|
var WebEnvironmentPlugin = require("./web/WebEnvironmentPlugin");
|
||||||
|
var WebpackOptionsApply = require("./WebpackOptionsApply");
|
||||||
|
var WebpackOptionsDefaulter = require("./WebpackOptionsDefaulter");
|
||||||
|
|
||||||
|
function webpack(options, callback) {
|
||||||
|
new WebpackOptionsDefaulter().process(options);
|
||||||
|
|
||||||
|
var compiler = new Compiler();
|
||||||
|
compiler.options = options;
|
||||||
|
compiler.options = new WebpackOptionsApply().process(options, compiler);
|
||||||
|
new WebEnvironmentPlugin(options.inputFileSystem, options.outputFileSystem).apply(compiler);
|
||||||
|
if(callback) {
|
||||||
|
compiler.run(callback);
|
||||||
|
}
|
||||||
|
return compiler;
|
||||||
|
}
|
||||||
|
module.exports = webpack;
|
||||||
|
|
||||||
|
webpack.WebpackOptionsDefaulter = WebpackOptionsDefaulter;
|
||||||
|
webpack.WebpackOptionsApply = WebpackOptionsApply;
|
||||||
|
webpack.Compiler = Compiler;
|
||||||
|
webpack.WebEnvironmentPlugin = WebEnvironmentPlugin;
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "webpack",
|
"name": "webpack",
|
||||||
"version": "0.11.0-beta12",
|
"version": "0.11.0-beta13",
|
||||||
"author": "Tobias Koppers @sokra",
|
"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.",
|
"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": {
|
"dependencies": {
|
||||||
|
@ -48,6 +48,7 @@
|
||||||
},
|
},
|
||||||
"homepage": "http://github.com/webpack/webpack",
|
"homepage": "http://github.com/webpack/webpack",
|
||||||
"main": "lib/webpack.js",
|
"main": "lib/webpack.js",
|
||||||
|
"web": "lib/webpack.web.js",
|
||||||
"bin": "./bin/webpack.js",
|
"bin": "./bin/webpack.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha --reporter spec"
|
"test": "mocha --reporter spec"
|
||||||
|
|
Loading…
Reference in New Issue