Socket
Socket
Sign inDemoInstall

extract-text-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extract-text-webpack-plugin - npm Package Compare versions

Comparing version 0.2.5 to 0.3.0

example/base.css

6

example/webpack.config.js

@@ -7,7 +7,7 @@ var ExtractTextPlugin = require("../");

path: __dirname + "/assets",
publicPath: "assets/"
publicPath: "/assets/"
},
module: {
loaders: [
{ test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader")},
{ test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader?sourceMap")},
{ test: /\.png$/, loader: "file-loader" }

@@ -17,4 +17,4 @@ ]

plugins: [
new ExtractTextPlugin("styles-[hash]-[chunkhash]-[name].css")
new ExtractTextPlugin("styles.css?[hash]-[chunkhash]-[name]")
]
};

@@ -5,5 +5,8 @@ /*

*/
var RawSource = require("webpack/lib/RawSource");
var SourceMapSource = require("webpack/lib/SourceMapSource");
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");

@@ -45,2 +48,13 @@ var nextId = 0;

ExtractTextPlugin.prototype.applyAdditionalInformation = function(node, info) {
if(info.length === 1 && info[0]) {
node = new SourceNode(null, null, null, [
"@media " + info[0] + " {",
node,
"}"
]);
}
return node;
};
ExtractTextPlugin.prototype.loader = function(options) {

@@ -72,7 +86,7 @@ options = JSON.parse(JSON.stringify(options || {}));

compilation.plugin("normal-module-loader", function(loaderContext, module) {
loaderContext[__dirname] = function(text, opt) {
if(typeof text !== "string" && text !== null)
loaderContext[__dirname] = function(content, opt) {
if(!Array.isArray(content) && content !== null)
throw new Error("Exported value is not a string.");
module.meta[__dirname] = {
text: text,
content: content,
options: opt

@@ -83,14 +97,14 @@ };

}.bind(this));
var texts;
var contents;
var filename = this.filename;
var id = this.id;
compilation.plugin("optimize-tree", function(chunks, modules, callback) {
texts = [];
contents = [];
async.forEach(chunks, function(chunk, callback) {
var shouldExtract = !!(options.allChunks || chunk.initial);
var text = [];
var content = [];
async.forEach(chunk.modules.slice(), function(module, callback) {
var meta = module.meta && module.meta[__dirname];
if(meta) {
var wasExtracted = typeof meta.text === "string";
var wasExtracted = Array.isArray(meta.content);
if(shouldExtract !== wasExtracted) {

@@ -104,12 +118,12 @@ module.meta[__dirname + "/extract"] = shouldExtract

meta = module.meta[__dirname];
if(typeof meta.text !== "string") {
var err = new Error(module.identifier() + " doesn't export text");
if(!Array.isArray(meta.content)) {
var err = new Error(module.identifier() + " doesn't export content");
compilation.errors.push(err);
return callback();
}
if(meta.text) text.push(meta.text);
if(meta.content) content.push(meta.content);
callback();
});
} else {
if(meta.text) text.push(meta.text);
if(meta.content) content.push(meta.content);
callback();

@@ -120,6 +134,6 @@ }

if(err) return callback(err);
if(text.length > 0) {
texts.push({
if(content.length > 0) {
contents.push({
chunk: chunk,
text: text
content: content
});

@@ -136,3 +150,3 @@ }

var assetContents = {};
texts.forEach(function(item) {
contents.forEach(function(item) {
var chunk = item.chunk;

@@ -143,11 +157,27 @@ var file = filename

.replace(Template.REGEXP_CHUNKHASH, chunk.renderedHash);
assetContents[file] = (assetContents[file] || []).concat(item.text);
assetContents[file] = (assetContents[file] || []).concat(item.content);
chunk.files.push(file);
});
Object.keys(assetContents).forEach(function(file) {
var text = assetContents[file].join("");
this.assets[file] = new RawSource(text);
var contained = {};
var content = assetContents[file].reduce(function(arr, items) {
return arr.concat(items);
}, []).filter(function(item) {
if(contained[item[0]]) return false;
contained[item[0]] = true;
return true;
}).map(function(item) {
var css = item[1];
var contents = item.slice(1).filter(function(i) { return typeof i === "string"; });
var sourceMap = typeof item[item.length-1] === "object" ? item[item.length-1] : undefined;
var text = contents.shift();
var node = sourceMap ? SourceNode.fromStringWithSourceMap(text, new SourceMapConsumer(sourceMap)) : new SourceNode(null, null, null, text);
return this.applyAdditionalInformation(node, contents);
}.bind(this));
var strAndMap = new SourceNode(null, null, null, content).toStringWithSourceMap();
compilation.assets[file] = new SourceMapSource(strAndMap.code, file, strAndMap.map.toJSON());
}.bind(this));
callback();
});
}.bind(this));
}.bind(this));
};

@@ -78,2 +78,11 @@ /*

var text = this.exec(source, request);
if(typeof text === "string")
text = [[0, text]];
text.forEach(function(item) {
var id = item[0];
compilation.modules.forEach(function(module) {
if(module.id === id)
item[0] = module.identifier();
});
});
this[__dirname](text, query);

@@ -80,0 +89,0 @@ } catch(e) {

{
"name": "extract-text-webpack-plugin",
"version": "0.2.5",
"version": "0.3.0",
"author": "Tobias Koppers @sokra",
"description": "Extract text from bundle into a file.",
"peerDependencies": {
"webpack": "^1.3"
"webpack": "^1.4"
},
"dependencies": {
"async": "0.2.x",
"loader-utils": "0.2.x"
"async": "~0.2.10",
"source-map": "~0.1.38",
"loader-utils": "~0.2.3"
},

@@ -16,3 +17,4 @@ "devDependencies": {

"style-loader": "*",
"css-loader": "*"
"css-loader": "*",
"webpack": "*"
},

@@ -30,2 +32,2 @@ "homepage": "http://github.com/webpack/extract-text-webpack-plugin",

]
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc