| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | var async = require("async"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function CachePlugin(cache) { | 
					
						
							|  |  |  | 	this.cache = cache || {}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module.exports = CachePlugin; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CachePlugin.prototype.apply = function(compiler) { | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 	if(Array.isArray(compiler.compilers)) { | 
					
						
							| 
									
										
										
										
											2014-06-19 05:02:33 +08:00
										 |  |  | 		compiler.compilers.forEach(function(c, idx) { | 
					
						
							|  |  |  | 			c.apply(new CachePlugin(this.cache[idx] = this.cache[idx] || {})); | 
					
						
							|  |  |  | 		}, this); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		compiler.plugin("compilation", function(compilation) { | 
					
						
							|  |  |  | 			compilation.cache = this.cache; | 
					
						
							|  |  |  | 		}.bind(this)); | 
					
						
							|  |  |  | 		compiler.plugin("run", function(compiler, callback) { | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 			if(!compiler._lastCompilationFileDependencies) return callback(); | 
					
						
							| 
									
										
										
										
											2014-06-19 05:02:33 +08:00
										 |  |  | 			var fs = compiler.inputFileSystem; | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 			var fileTs = compiler.fileTimestamps = {}; | 
					
						
							| 
									
										
										
										
											2014-06-19 05:02:33 +08:00
										 |  |  | 			async.forEach(compiler._lastCompilationFileDependencies, function(file, callback) { | 
					
						
							|  |  |  | 				fs.stat(file, function(err, stat) { | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 					if(err) { | 
					
						
							|  |  |  | 						if(err.code === "ENOENT") return callback(); | 
					
						
							| 
									
										
										
										
											2014-06-19 05:02:33 +08:00
										 |  |  | 						return callback(err); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-19 05:02:33 +08:00
										 |  |  | 					fileTs[file] = stat.mtime || Infinity; | 
					
						
							|  |  |  | 					callback(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}, callback); | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-06-19 05:02:33 +08:00
										 |  |  | 		compiler.plugin("after-compile", function(compilation, callback) { | 
					
						
							|  |  |  | 			compilation.compiler._lastCompilationFileDependencies = compilation.fileDependencies; | 
					
						
							|  |  |  | 			compilation.compiler._lastCompilationContextDependencies = compilation.contextDependencies; | 
					
						
							|  |  |  | 			callback(); | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-06-19 05:02:33 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | }; |