| 
									
										
										
										
											2012-03-12 04:50:55 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | var Compiler = require("./Compiler"); | 
					
						
							| 
									
										
										
										
											2014-06-12 04:26:50 +08:00
										 |  |  | var MultiCompiler = require("./MultiCompiler"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | var NodeEnvironmentPlugin = require("./node/NodeEnvironmentPlugin"); | 
					
						
							|  |  |  | var WebpackOptionsApply = require("./WebpackOptionsApply"); | 
					
						
							|  |  |  | var WebpackOptionsDefaulter = require("./WebpackOptionsDefaulter"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function webpack(options, callback) { | 
					
						
							| 
									
										
										
										
											2014-06-12 04:26:50 +08:00
										 |  |  | 	var compiler; | 
					
						
							|  |  |  | 	if(Array.isArray(options)) { | 
					
						
							|  |  |  | 		compiler = new MultiCompiler(options.map(function(options) { | 
					
						
							|  |  |  | 			return webpack(options); | 
					
						
							|  |  |  | 		})); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		new WebpackOptionsDefaulter().process(options); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-12 04:26:50 +08:00
										 |  |  | 		compiler = new Compiler(); | 
					
						
							|  |  |  | 		compiler.options = options; | 
					
						
							|  |  |  | 		compiler.options = new WebpackOptionsApply().process(options, compiler); | 
					
						
							|  |  |  | 		new NodeEnvironmentPlugin().apply(compiler); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	if(callback) { | 
					
						
							| 
									
										
										
										
											2012-09-25 22:45:53 +08:00
										 |  |  | 		if(options.watch) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			return compiler.watch(options.watchDelay, callback); | 
					
						
							| 
									
										
										
										
											2012-09-25 22:45:53 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			compiler.run(callback); | 
					
						
							| 
									
										
										
										
											2012-03-10 20:11:23 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-10-20 21:08:12 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	return compiler; | 
					
						
							| 
									
										
										
										
											2012-05-07 15:01:28 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-12-18 06:21:49 +08:00
										 |  |  | exports = module.exports = webpack; | 
					
						
							| 
									
										
										
										
											2012-05-07 15:01:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | webpack.WebpackOptionsDefaulter = WebpackOptionsDefaulter; | 
					
						
							|  |  |  | webpack.WebpackOptionsApply = WebpackOptionsApply; | 
					
						
							|  |  |  | webpack.Compiler = Compiler; | 
					
						
							| 
									
										
										
										
											2014-06-12 04:26:50 +08:00
										 |  |  | webpack.MultiCompiler = MultiCompiler; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | webpack.NodeEnvironmentPlugin = NodeEnvironmentPlugin; | 
					
						
							| 
									
										
										
										
											2013-12-18 06:21:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function exportPlugins(exports, path, plugins) { | 
					
						
							|  |  |  | 	plugins.forEach(function(name) { | 
					
						
							|  |  |  | 		Object.defineProperty(exports, name, { | 
					
						
							|  |  |  | 			configurable: false, | 
					
						
							|  |  |  | 			enumerable: true, | 
					
						
							|  |  |  | 			get: function() { | 
					
						
							|  |  |  | 				return require(path + "/" + name); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exportPlugins(exports, ".", [ | 
					
						
							|  |  |  | 	"DefinePlugin", | 
					
						
							|  |  |  | 	"NormalModuleReplacementPlugin", | 
					
						
							|  |  |  | 	"ContextReplacementPlugin", | 
					
						
							|  |  |  | 	"IgnorePlugin", | 
					
						
							|  |  |  | 	"BannerPlugin", | 
					
						
							|  |  |  | 	"PrefetchPlugin", | 
					
						
							|  |  |  | 	"ProvidePlugin", | 
					
						
							|  |  |  | 	"HotModuleReplacementPlugin", | 
					
						
							| 
									
										
										
										
											2014-01-21 20:07:10 +08:00
										 |  |  | 	"ResolverPlugin", | 
					
						
							| 
									
										
										
										
											2014-06-24 06:41:10 +08:00
										 |  |  | 	"SourceMapDevToolPlugin", | 
					
						
							|  |  |  | 	"EvalDevToolModulePlugin", | 
					
						
							|  |  |  | 	"CachePlugin", | 
					
						
							|  |  |  | 	"ExternalsPlugin", | 
					
						
							|  |  |  | 	"JsonpTemplatePlugin", | 
					
						
							|  |  |  | 	"LibraryTemplatePlugin", | 
					
						
							|  |  |  | 	"LoaderTargetPlugin", | 
					
						
							|  |  |  | 	"MemoryOutputFileSystem", | 
					
						
							|  |  |  | 	"ProgressPlugin", | 
					
						
							|  |  |  | 	"SetVarMainTemplatePlugin", | 
					
						
							|  |  |  | 	"UmdMainTemplatePlugin", | 
					
						
							| 
									
										
										
										
											2013-12-18 06:21:49 +08:00
										 |  |  | ]); | 
					
						
							|  |  |  | exportPlugins(exports.optimize = {}, "./optimize", [ | 
					
						
							| 
									
										
										
										
											2014-02-05 19:37:37 +08:00
										 |  |  | 	"AggressiveMergingPlugin", | 
					
						
							| 
									
										
										
										
											2013-12-18 06:21:49 +08:00
										 |  |  | 	"CommonsChunkPlugin", | 
					
						
							|  |  |  | 	"DedupePlugin", | 
					
						
							|  |  |  | 	"LimitChunkCountPlugin", | 
					
						
							|  |  |  | 	"MinChunkSizePlugin", | 
					
						
							|  |  |  | 	"OccurenceOrderPlugin", | 
					
						
							| 
									
										
										
										
											2014-02-25 15:51:40 +08:00
										 |  |  | 	"OccurrenceOrderPlugin", | 
					
						
							| 
									
										
										
										
											2013-12-18 06:21:49 +08:00
										 |  |  | 	"UglifyJsPlugin" | 
					
						
							|  |  |  | ]); | 
					
						
							|  |  |  | exportPlugins(exports.dependencies = {}, "./dependencies", [ | 
					
						
							|  |  |  | 	"LabeledModulesPlugin" | 
					
						
							|  |  |  | ]); |