From 84b4321fb60de1f9c5c792c6d6aa22a0bdaedb68 Mon Sep 17 00:00:00 2001 From: Josh Johnston Date: Mon, 29 Jun 2015 10:22:13 +1000 Subject: [PATCH 1/4] append a hash of the css source to scoped classnames --- index.js | 18 ++++++++++++++++++ package.json | 1 + 2 files changed, 19 insertions(+) diff --git a/index.js b/index.js index 5998b52..c9a2340 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,19 @@ var through = require('through'); var Core = require('css-modules-loader-core'); var FileSystemLoader = require('css-modules-loader-core/lib/file-system-loader'); var assign = require('object-assign'); +var stringHash = require('string-hash'); + +/* + Custom `generateScopedName` function for `postcss-modules-scope`. + Appends a hash of the css source. +*/ +function createNameFunc (plugin) { + var orig = plugin.generateScopedName; + return function (name, path, css) { + var hash = stringHash(css).toString(36).substr(0, 5); + return orig.apply(plugin, arguments) + '___' + hash; + } +}; var cssExt = /\.css$/; module.exports = function (browserify, options) { @@ -31,6 +44,11 @@ module.exports = function (browserify, options) { var plugin = require(name); + // custom scoped name generation + if (name === 'postcss-modules-scope') { + options[name].generateScopedName = createScopedNameFunc(plugin); + } + if (name in options) { plugin = plugin(options[name]); } else { diff --git a/package.json b/package.json index 419f84f..47ba17a 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "dependencies": { "css-modules-loader-core": "0.0.10", "object-assign": "^3.0.0", + "string-hash": "^1.1.0", "through": "^2.3.7" }, "devDependencies": {}, From 2fd62bf501e5baefa39ad89985c0e6d64b0348d0 Mon Sep 17 00:00:00 2001 From: Josh Johnston Date: Mon, 29 Jun 2015 12:18:22 +1000 Subject: [PATCH 2/4] fixed typo --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index c9a2340..814118d 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ var stringHash = require('string-hash'); Custom `generateScopedName` function for `postcss-modules-scope`. Appends a hash of the css source. */ -function createNameFunc (plugin) { +function createScopedNameFunc (plugin) { var orig = plugin.generateScopedName; return function (name, path, css) { var hash = stringHash(css).toString(36).substr(0, 5); From 6bf3955e67bce0e85b005f9d8d7a47c72a7e0ad3 Mon Sep 17 00:00:00 2001 From: Josh Johnston Date: Mon, 29 Jun 2015 12:24:23 +1000 Subject: [PATCH 3/4] ensure options object is initialized --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 814118d..d6f6bef 100644 --- a/index.js +++ b/index.js @@ -46,6 +46,7 @@ module.exports = function (browserify, options) { // custom scoped name generation if (name === 'postcss-modules-scope') { + options[name] = options[name] || {}; options[name].generateScopedName = createScopedNameFunc(plugin); } From 6b103633a8959d6cab6a8429c72530ed2b0222fa Mon Sep 17 00:00:00 2001 From: Josh Johnston Date: Thu, 2 Jul 2015 20:18:05 +1000 Subject: [PATCH 4/4] upgraded css-modules-loader-core --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47ba17a..80d17d2 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A browserify transform to load CSS Modules", "main": "index.js", "dependencies": { - "css-modules-loader-core": "0.0.10", + "css-modules-loader-core": "0.0.11", "object-assign": "^3.0.0", "string-hash": "^1.1.0", "through": "^2.3.7"