Skip to content

append a hash of the css source to scoped classnames #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 createScopedNameFunc (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) {
Expand Down Expand Up @@ -31,6 +44,12 @@ module.exports = function (browserify, options) {

var plugin = require(name);

// custom scoped name generation
if (name === 'postcss-modules-scope') {
options[name] = options[name] || {};
options[name].generateScopedName = createScopedNameFunc(plugin);
}

if (name in options) {
plugin = plugin(options[name]);
} else {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"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"
},
"devDependencies": {},
Expand Down