extract-text-webpack-plugin
Advanced tools
Comparing version 0.6.0 to 0.7.0
171
index.js
@@ -6,7 +6,3 @@ /* | ||
var ConcatSource = require("webpack/lib/ConcatSource"); | ||
var Template = require("webpack/lib/Template"); | ||
var async = require("async"); | ||
var SourceNode = require("source-map").SourceNode; | ||
var SourceMapConsumer = require("source-map").SourceMapConsumer; | ||
var ModuleFilenameHelpers = require("webpack/lib/ModuleFilenameHelpers"); | ||
var ExtractedModule = require("./ExtractedModule"); | ||
@@ -19,2 +15,74 @@ var Chunk = require("webpack/lib/Chunk"); | ||
function ExtractTextPluginCompilation() { | ||
this.modulesByIdentifier = {}; | ||
} | ||
ExtractTextPlugin.prototype.mergeNonInitialChunks = function(chunk, intoChunk, checkedChunks) { | ||
if(!intoChunk) { | ||
checkedChunks = []; | ||
chunk.chunks.forEach(function(c) { | ||
if(c.initial) return; | ||
this.mergeNonInitialChunks(c, chunk, checkedChunks); | ||
}, this); | ||
} else if(checkedChunks.indexOf(chunk) < 0) { | ||
checkedChunks.push(chunk); | ||
chunk.modules.slice().forEach(function(module) { | ||
chunk.removeModule(module); | ||
intoChunk.addModule(module); | ||
module.addChunk(intoChunk); | ||
}); | ||
chunk.chunks.forEach(function(c) { | ||
if(c.initial) return; | ||
this.mergeNonInitialChunks(c, intoChunk, checkedChunks); | ||
}, this); | ||
} | ||
}; | ||
ExtractTextPluginCompilation.prototype.addModule = function(identifier, originalModule, source, additionalInformation, sourceMap, prevModules) { | ||
var m; | ||
if(!this.modulesByIdentifier[identifier]) { | ||
m = this.modulesByIdentifier[identifier] = new ExtractedModule(identifier, originalModule, source, sourceMap, additionalInformation, prevModules); | ||
} else { | ||
m = this.modulesByIdentifier[identifier]; | ||
m.addPrevModules(prevModules); | ||
} | ||
return m; | ||
}; | ||
ExtractTextPluginCompilation.prototype.addResultToChunk = function(identifier, result, originalModule, extractedChunk) { | ||
if(!Array.isArray(result)) { | ||
result = [[identifier, result]]; | ||
} | ||
var counterMap = {}; | ||
var prevModules = []; | ||
result.forEach(function(item) { | ||
var c = counterMap[item[0]]; | ||
var module = this.addModule.call(this, item[0] + (c || ""), originalModule, item[1], item[2], item[3], prevModules.slice()); | ||
extractedChunk.addModule(module); | ||
module.addChunk(extractedChunk); | ||
counterMap[item[0]] = (c || 0) + 1; | ||
prevModules.push(module); | ||
}, this); | ||
}; | ||
ExtractTextPlugin.prototype.renderExtractedChunk = function(chunk) { | ||
var source = new ConcatSource(); | ||
chunk.modules.forEach(function(module) { | ||
source.add(this.applyAdditionalInformation(module.source(), module.additionalInformation)); | ||
}, this); | ||
return source; | ||
}; | ||
function getOrder(a, b) { | ||
var bBeforeA = a.getPrevModules().indexOf(b) >= 0; | ||
var aBeforeB = b.getPrevModules().indexOf(a) >= 0; | ||
if(aBeforeB && bBeforeA) | ||
return NaN; | ||
if(bBeforeA) | ||
return 1; | ||
if(aBeforeB) | ||
return -1; | ||
return 0; | ||
} | ||
function ExtractTextPlugin(id, filename, options) { | ||
@@ -39,3 +107,3 @@ if(typeof filename !== "string") { | ||
return a; | ||
}; | ||
} | ||
@@ -111,6 +179,5 @@ ExtractTextPlugin.loader = function(options) { | ||
}; | ||
return options.allChunks || module.meta[__dirname + "/extract"]; | ||
return options.allChunks || module.meta[__dirname + "/extract"]; // eslint-disable-line no-path-concat | ||
}; | ||
}.bind(this)); | ||
var contents; | ||
}); | ||
var filename = this.filename; | ||
@@ -126,6 +193,5 @@ var id = this.id; | ||
}); | ||
}.bind(this)); | ||
}); | ||
compilation.plugin("optimize-tree", function(chunks, modules, callback) { | ||
contents = []; | ||
extractedChunks = chunks.map(function(chunk) { | ||
extractedChunks = chunks.map(function() { | ||
return new Chunk(); | ||
@@ -165,3 +231,3 @@ }); | ||
if(shouldExtract !== wasExtracted) { | ||
module.meta[__dirname + "/extract"] = shouldExtract | ||
module.meta[__dirname + "/extract"] = shouldExtract; // eslint-disable-line no-path-concat | ||
compilation.rebuildModule(module, function(err) { | ||
@@ -174,3 +240,3 @@ if(err) { | ||
if(!Array.isArray(meta.content)) { | ||
var err = new Error(module.identifier() + " doesn't export content"); | ||
err = new Error(module.identifier() + " doesn't export content"); | ||
compilation.errors.push(err); | ||
@@ -182,3 +248,3 @@ return callback(); | ||
callback(); | ||
}.bind(this)); | ||
}); | ||
} else { | ||
@@ -190,7 +256,7 @@ if(meta.content) | ||
} else callback(); | ||
}.bind(this), function(err) { | ||
}, function(err) { | ||
if(err) return callback(err); | ||
callback(); | ||
}.bind(this)); | ||
}.bind(this), function(err) { | ||
}); | ||
}, function(err) { | ||
if(err) return callback(err); | ||
@@ -206,3 +272,2 @@ extractedChunks.forEach(function(extractedChunk) { | ||
compilation.plugin("additional-assets", function(callback) { | ||
var assetContents = {}; | ||
extractedChunks.forEach(function(extractedChunk) { | ||
@@ -241,71 +306,1 @@ if(extractedChunk.modules.length) { | ||
}; | ||
function ExtractTextPluginCompilation() { | ||
this.modulesByIdentifier = {}; | ||
} | ||
ExtractTextPlugin.prototype.mergeNonInitialChunks = function(chunk, intoChunk, checkedChunks) { | ||
if(!intoChunk) { | ||
checkedChunks = []; | ||
chunk.chunks.forEach(function(c) { | ||
if(c.initial) return; | ||
this.mergeNonInitialChunks(c, chunk, checkedChunks); | ||
}, this); | ||
} else if(checkedChunks.indexOf(chunk) < 0) { | ||
checkedChunks.push(chunk); | ||
chunk.modules.slice().forEach(function(module) { | ||
chunk.removeModule(module); | ||
intoChunk.addModule(module); | ||
module.addChunk(intoChunk); | ||
}); | ||
chunk.chunks.forEach(function(c) { | ||
if(c.initial) return; | ||
this.mergeNonInitialChunks(c, intoChunk, checkedChunks); | ||
}, this); | ||
} | ||
}; | ||
ExtractTextPluginCompilation.prototype.addModule = function(identifier, originalModule, source, additionalInformation, sourceMap, prevModules) { | ||
if(!this.modulesByIdentifier[identifier]) | ||
return this.modulesByIdentifier[identifier] = new ExtractedModule(identifier, originalModule, source, sourceMap, additionalInformation, prevModules); | ||
var m = this.modulesByIdentifier[identifier]; | ||
m.addPrevModules(prevModules); | ||
return m; | ||
}; | ||
ExtractTextPluginCompilation.prototype.addResultToChunk = function(identifier, result, originalModule, extractedChunk) { | ||
if(!Array.isArray(result)) { | ||
result = [[identifier, result]]; | ||
} | ||
var counterMap = {}; | ||
var prevModules = []; | ||
result.forEach(function(item) { | ||
var c = counterMap[item[0]]; | ||
var i = item.slice(); | ||
var module = this.addModule.call(this, item[0] + (c || ""), originalModule, item[1], item[2], item[3], prevModules.slice()); | ||
extractedChunk.addModule(module); | ||
module.addChunk(extractedChunk); | ||
counterMap[item[0]] = (c || 0) + 1; | ||
prevModules.push(module); | ||
}, this); | ||
}; | ||
ExtractTextPlugin.prototype.renderExtractedChunk = function(chunk) { | ||
var source = new ConcatSource(); | ||
chunk.modules.forEach(function(module) { | ||
source.add(this.applyAdditionalInformation(module.source(), module.additionalInformation)); | ||
}, this); | ||
return source; | ||
}; | ||
function getOrder(a, b) { | ||
var bBeforeA = a.getPrevModules().indexOf(b) >= 0; | ||
var aBeforeB = b.getPrevModules().indexOf(a) >= 0; | ||
if(aBeforeB && bBeforeA) | ||
return NaN; | ||
if(bBeforeA) | ||
return 1; | ||
if(aBeforeB) | ||
return -1; | ||
return 0; | ||
} |
@@ -12,7 +12,7 @@ /* | ||
module.exports = function(source) { | ||
this.cacheable && this.cacheable(); | ||
if(this.cacheable) this.cacheable(); | ||
return source; | ||
}; | ||
module.exports.pitch = function(request, preReq, data) { | ||
this.cacheable && this.cacheable(); | ||
module.exports.pitch = function(request) { | ||
if(this.cacheable) this.cacheable(); | ||
var query = loaderUtils.parseQuery(this.query); | ||
@@ -33,11 +33,12 @@ this.addDependency(this.resourcePath); | ||
} | ||
var resultSource; | ||
if(query.remove) { | ||
var resultSource = "// removed by extract-text-webpack-plugin"; | ||
resultSource = "// removed by extract-text-webpack-plugin"; | ||
} else { | ||
var resultSource = undefined; | ||
resultSource = undefined; | ||
} | ||
if(query.extract !== false) { | ||
var childFilename = __dirname + " " + request; | ||
var publicPath = typeof query.publicPath === "string" ? query.publicPath : this._compilation.outputOptions.publicPath | ||
var childFilename = __dirname + " " + request; // eslint-disable-line no-path-concat | ||
var publicPath = typeof query.publicPath === "string" ? query.publicPath : this._compilation.outputOptions.publicPath; | ||
var outputOptions = { | ||
@@ -53,3 +54,3 @@ filename: childFilename, | ||
childCompiler.apply(new LimitChunkCountPlugin({ maxChunks: 1 })); | ||
var subCache = "subcache " + __dirname + " " + request; | ||
var subCache = "subcache " + __dirname + " " + request; // eslint-disable-line no-path-concat | ||
childCompiler.plugin("compilation", function(compilation) { | ||
@@ -65,3 +66,3 @@ if(compilation.cache) { | ||
childCompiler.plugin("this-compilation", function(compilation) { | ||
compilation.plugin("normal-module-loader", function(loaderContext, module) { | ||
compilation.plugin("normal-module-loader", function(loaderContext) { | ||
loaderContext[__dirname] = false; | ||
@@ -82,3 +83,3 @@ }); | ||
callback(); | ||
}.bind(this)) | ||
}); | ||
var callback = this.async(); | ||
@@ -109,4 +110,4 @@ childCompiler.runAsChild(function(err, entries, compilation) { | ||
this[__dirname](text, query); | ||
if(text.placeholders && typeof resultSource !== "undefined") { | ||
resultSource += "\nmodule.exports = " + JSON.stringify(text.placeholders) + ";"; | ||
if(text.locals && typeof resultSource !== "undefined") { | ||
resultSource += "\nmodule.exports = " + JSON.stringify(text.locals) + ";"; | ||
} | ||
@@ -113,0 +114,0 @@ } catch(e) { |
{ | ||
"name": "extract-text-webpack-plugin", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"author": "Tobias Koppers @sokra", | ||
@@ -5,0 +5,0 @@ "description": "Extract text from bundle into a file.", |
8
19705
457