From 7ead6e84965bf79934090cfbad63fedf100cbab8 Mon Sep 17 00:00:00 2001
From: Istvan Jano <janoist1@gmail.com>
Date: Sun, 24 Jul 2016 17:20:42 +0100
Subject: [PATCH 1/6] Implement ability to be used on server side - For
 universal apps

---
 README.md          | 16 ++++++++++++++++
 addStylesServer.js | 22 ++++++++++++++++++++++
 index.js           |  5 ++++-
 package.json       | 25 +++++++++++++++++++++----
 4 files changed, 63 insertions(+), 5 deletions(-)
 create mode 100644 addStylesServer.js

diff --git a/README.md b/README.md
index 4f66e90a..4001cef8 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,22 @@ Styles are not added on `require`, but instead on call to `use`/`ref`. Styles ar
 
 Note: Behavior is undefined when `unuse`/`unref` is called more often than `use`/`ref`. Don't do that.
 
+### Server environment
+
+On server side we can't load styles into the DOM but to collect them and use when assembling the layout. 
+
+Example with React:
+
+``` javascript
+<head>
+    <title>React Redux Starter Kit</title>
+    { global.__styles__.map(style =>
+      <style key={style.id}
+             type="text/css">{style.parts.map(part => part.css + "\n")}</style>)
+    }
+</head>
+```
+
 ### Options
 
 #### `insertAt`
diff --git a/addStylesServer.js b/addStylesServer.js
new file mode 100644
index 00000000..10f3a833
--- /dev/null
+++ b/addStylesServer.js
@@ -0,0 +1,22 @@
+/*
+	MIT License http://www.opensource.org/licenses/mit-license.php
+	Istvan Jano janoist1@gmail.com
+*/
+module.exports.addStylesServer = function(list, options) {
+	global.__styles__ = global.__styles__ || [];
+	var newStyles = {};
+
+	for(var i = 0; i < list.length; i++) {
+		var item = list[i];
+		var id = item[0];
+		var css = item[1];
+		var media = item[2];
+		var sourceMap = item[3];
+		var part = {css: css, media: media, sourceMap: sourceMap};
+
+		if(!newStyles[id])
+			global.__styles__.push(newStyles[id] = {id: id, parts: [part]});
+		else
+			newStyles[id].parts.push(part);
+	}
+}
\ No newline at end of file
diff --git a/index.js b/index.js
index 2b12838d..ccc1f7f3 100644
--- a/index.js
+++ b/index.js
@@ -15,8 +15,11 @@ module.exports.pitch = function(remainingRequest) {
 		"var content = require(" + loaderUtils.stringifyRequest(this, "!!" + remainingRequest) + ");",
 		"if(typeof content === 'string') content = [[module.id, content, '']];",
 		"// add the styles to the DOM",
-		"var update = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "addStyles.js")) + ")(content, " + JSON.stringify(query) + ");",
 		"if(content.locals) module.exports = content.locals;",
+		"if (typeof window === 'undefined') {",
+		"   require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "addStylesServer.js")) + ")(content, " + JSON.stringify(query) + ");",
+		"} else {",
+		"var update = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "addStyles.js")) + ")(content, " + JSON.stringify(query) + ");",
 		"// Hot Module Replacement",
 		"if(module.hot) {",
 		"	// When the styles change, update the <style> tags",
diff --git a/package.json b/package.json
index 6bb4392c..ce29e7e6 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
-  "name": "style-loader",
-  "version": "0.13.1",
-  "author": "Tobias Koppers @sokra",
+  "name": "simple-universal-style-loader",
+  "version": "0.14.0",
+  "author": "Tobias Koppers @sokra & Istvan Jano @janoist1",
   "description": "style loader module for webpack",
   "devDependencies": {
     "css-loader": "~0.8.0"
@@ -13,5 +13,22 @@
   "license": "MIT",
   "dependencies": {
     "loader-utils": "^0.2.7"
-  }
+  },
+  "bugs": {
+    "url": "https://github.com/webpack/style-loader/issues"
+  },
+  "homepage": "https://github.com/webpack/style-loader",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "keywords": [
+    "universal",
+    "isomorphic",
+    "client",
+    "server",
+    "style",
+    "loader",
+    "webpack"
+  ]
 }

From ec63c270a01232bc93cb060fa665ff394040ff61 Mon Sep 17 00:00:00 2001
From: Istvan Jano <janoist1@gmail.com>
Date: Sun, 24 Jul 2016 17:38:36 +0100
Subject: [PATCH 2/6] Ignore folder .idea

---
 .gitignore | 3 ++-
 .npmignore | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index 30bc1627..551af95c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-/node_modules
\ No newline at end of file
+/node_modules
+.idea
diff --git a/.npmignore b/.npmignore
index 67fc140b..66befaa9 100644
--- a/.npmignore
+++ b/.npmignore
@@ -1 +1,2 @@
 fixtures/
+.idea

From 273915156936fae8aec9f9ae17e0f7a6f7a945e0 Mon Sep 17 00:00:00 2001
From: Istvan Jano <janoist1@gmail.com>
Date: Sun, 24 Jul 2016 17:39:27 +0100
Subject: [PATCH 3/6] Fix missing block close '}'

---
 index.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js
index ccc1f7f3..94aa006d 100644
--- a/index.js
+++ b/index.js
@@ -14,11 +14,11 @@ module.exports.pitch = function(remainingRequest) {
 		"// load the styles",
 		"var content = require(" + loaderUtils.stringifyRequest(this, "!!" + remainingRequest) + ");",
 		"if(typeof content === 'string') content = [[module.id, content, '']];",
-		"// add the styles to the DOM",
 		"if(content.locals) module.exports = content.locals;",
 		"if (typeof window === 'undefined') {",
 		"   require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "addStylesServer.js")) + ")(content, " + JSON.stringify(query) + ");",
 		"} else {",
+		"// add the styles to the DOM",
 		"var update = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "addStyles.js")) + ")(content, " + JSON.stringify(query) + ");",
 		"// Hot Module Replacement",
 		"if(module.hot) {",
@@ -32,6 +32,7 @@ module.exports.pitch = function(remainingRequest) {
 		"	}",
 		"	// When the module is disposed, remove the <style> tags",
 		"	module.hot.dispose(function() { update(); });",
+		"}",
 		"}"
 	].join("\n");
 };

From 21b29c76354c808575d4d93ea9baf98dee9ee232 Mon Sep 17 00:00:00 2001
From: Istvan Jano <janoist1@gmail.com>
Date: Sun, 24 Jul 2016 17:39:50 +0100
Subject: [PATCH 4/6] Increase version to 0.14.2

---
 package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/package.json b/package.json
index ce29e7e6..fd4e6903 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "simple-universal-style-loader",
-  "version": "0.14.0",
+  "version": "0.14.2",
   "author": "Tobias Koppers @sokra & Istvan Jano @janoist1",
   "description": "style loader module for webpack",
   "devDependencies": {

From d6e4da256582bedb66ddd34e87e13eeb6c7aed04 Mon Sep 17 00:00:00 2001
From: Istvan Jano <janoist1@gmail.com>
Date: Sun, 24 Jul 2016 17:48:07 +0100
Subject: [PATCH 5/6] Update README

---
 README.md    | 14 +++++++-------
 package.json |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index 4001cef8..ccb31e08 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ Adds CSS to the DOM by injecting a `<style>` tag
 ### Simple API
 
 ``` javascript
-require("style!raw!./file.css");
+require("simple-universal-style!raw!./file.css");
 // => add rules in file.css to document
 ```
 
@@ -18,7 +18,7 @@ It's recommended to combine it with the [`css-loader`](https://github.com/webpac
 It's also possible to add a URL instead of a CSS string:
 
 ``` javascript
-require("style/url!file!./file.css");
+require("simple-universal-style/url!file!./file.css");
 // => add a <link rel="stylesheet"> to file.css to document
 ```
 
@@ -29,14 +29,14 @@ require("style/url!file!./file.css");
 When using [local scope CSS](https://github.com/webpack/css-loader#local-scope) the module exports the generated identifiers:
 
 ``` javascript
-var style = require("style!css!./file.css");
+var style = require("simple-universal-style!css!./file.css");
 style.placeholder1 === "z849f98ca812bc0d099a43e0f90184"
 ```
 
 ### Reference-counted API
 
 ``` javascript
-var style = require("style/useable!css!./file.css");
+var style = require("simple-universal-style/useable!css!./file.css");
 style.use(); // = style.ref();
 style.unuse(); // = style.unref();
 ```
@@ -81,8 +81,8 @@ So the recommended configuration for webpack is:
 {
   module: {
     loaders: [
-      { test: /\.css$/, exclude: /\.useable\.css$/, loader: "style!css" },
-      { test: /\.useable\.css$/, loader: "style/useable!css" }
+      { test: /\.css$/, exclude: /\.useable\.css$/, loader: "simple-universal-style!css" },
+      { test: /\.useable\.css$/, loader: "simple-universal-style/useable!css" }
     ]
   }
 }
@@ -93,7 +93,7 @@ So the recommended configuration for webpack is:
 ## Install
 
 ```
-npm install style-loader
+npm install simple-universal-style-loader
 ```
 
 ## License
diff --git a/package.json b/package.json
index fd4e6903..58f1f734 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "simple-universal-style-loader",
-  "version": "0.14.2",
+  "version": "0.14.3",
   "author": "Tobias Koppers @sokra & Istvan Jano @janoist1",
   "description": "style loader module for webpack",
   "devDependencies": {

From b8edfa7f17c943a23f115581f122262865baf135 Mon Sep 17 00:00:00 2001
From: Istvan Jano <janoist1@gmail.com>
Date: Tue, 26 Jul 2016 09:49:11 +0100
Subject: [PATCH 6/6] Some refactor: added getStyle and separated server code

---
 README.md          |  6 ++++++
 addStylesServer.js | 22 ----------------------
 index.js           | 13 ++++++++-----
 package.json       |  4 ++--
 universal.js       | 39 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 55 insertions(+), 29 deletions(-)
 delete mode 100644 addStylesServer.js
 create mode 100644 universal.js

diff --git a/README.md b/README.md
index ccb31e08..0e037722 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,12 @@ Example with React:
 </head>
 ```
 
+From version 0.14.4 the captured styles can be get by using `getStyles()` as well:
+
+``` javascript
+import { getStyles } from 'simple-universal-style-loader'
+```
+
 ### Options
 
 #### `insertAt`
diff --git a/addStylesServer.js b/addStylesServer.js
deleted file mode 100644
index 10f3a833..00000000
--- a/addStylesServer.js
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
-	MIT License http://www.opensource.org/licenses/mit-license.php
-	Istvan Jano janoist1@gmail.com
-*/
-module.exports.addStylesServer = function(list, options) {
-	global.__styles__ = global.__styles__ || [];
-	var newStyles = {};
-
-	for(var i = 0; i < list.length; i++) {
-		var item = list[i];
-		var id = item[0];
-		var css = item[1];
-		var media = item[2];
-		var sourceMap = item[3];
-		var part = {css: css, media: media, sourceMap: sourceMap};
-
-		if(!newStyles[id])
-			global.__styles__.push(newStyles[id] = {id: id, parts: [part]});
-		else
-			newStyles[id].parts.push(part);
-	}
-}
\ No newline at end of file
diff --git a/index.js b/index.js
index 94aa006d..6f17eb64 100644
--- a/index.js
+++ b/index.js
@@ -1,9 +1,10 @@
 /*
-	MIT License http://www.opensource.org/licenses/mit-license.php
-	Author Tobias Koppers @sokra
-*/
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+ */
 var loaderUtils = require("loader-utils"),
-	path = require("path");
+	path = require("path"),
+	universal = require('./universal');
 module.exports = function() {};
 module.exports.pitch = function(remainingRequest) {
 	if(this.cacheable) this.cacheable();
@@ -16,7 +17,7 @@ module.exports.pitch = function(remainingRequest) {
 		"if(typeof content === 'string') content = [[module.id, content, '']];",
 		"if(content.locals) module.exports = content.locals;",
 		"if (typeof window === 'undefined') {",
-		"   require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "addStylesServer.js")) + ")(content, " + JSON.stringify(query) + ");",
+		"   require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "universal.js")) + ").addStyles(content, " + JSON.stringify(query) + ");",
 		"} else {",
 		"// add the styles to the DOM",
 		"var update = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "addStyles.js")) + ")(content, " + JSON.stringify(query) + ");",
@@ -36,3 +37,5 @@ module.exports.pitch = function(remainingRequest) {
 		"}"
 	].join("\n");
 };
+
+module.exports.getStyles = universal.getStyles
\ No newline at end of file
diff --git a/package.json b/package.json
index 58f1f734..4bbf3af1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "simple-universal-style-loader",
-  "version": "0.14.3",
+  "version": "0.14.4",
   "author": "Tobias Koppers @sokra & Istvan Jano @janoist1",
   "description": "style loader module for webpack",
   "devDependencies": {
@@ -8,7 +8,7 @@
   },
   "repository": {
     "type": "git",
-    "url": "git@github.com:webpack/style-loader.git"
+    "url": "git@github.com:janoist1/simple-universal-style-loader.git"
   },
   "license": "MIT",
   "dependencies": {
diff --git a/universal.js b/universal.js
new file mode 100644
index 00000000..f16e9c18
--- /dev/null
+++ b/universal.js
@@ -0,0 +1,39 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Istvan Jano janoist1@gmail.com
+ */
+
+/**
+ * Add styles - used by the loader
+ *
+ * @param list
+ * @param options
+ */
+module.exports.addStyles = function (list, options) {
+    global.__styles__ = global.__styles__ || []
+    var newStyles = {}
+
+    for (var i = 0; i < list.length; i++) {
+        var item = list[i]
+        var id = item[0]
+        var css = item[1]
+        var media = item[2]
+        var sourceMap = item[3]
+        var part = {css: css, media: media, sourceMap: sourceMap}
+
+        if (!newStyles[id]){
+            global.__styles__.push(newStyles[id] = {id: id, parts: [part]})
+        } else {
+            newStyles[id].parts.push(part)
+        }
+    }
+}
+
+/**
+ * Return the styles that have been collected so far
+ *
+ * @returns {*}
+ */
+module.exports.getStyles = function () {
+    return global.__styles__
+}
