geordiemhall / rework-namespace-css Goto Github PK
View Code? Open in Web Editor NEWPlugin for rework that namespaces CSS with selectors and class prefixes.
Plugin for rework that namespaces CSS with selectors and class prefixes.
Code used:
var gulp = require("gulp");
var rework = require('rework')
rework.namespace = require('rework-namespace-css')
return gulp.src('./style.css')
.pipe(rework(rework.namespace({ selector: '.gmh', class: 'gmh-' })))
.pipe(gulp.dest('dist/styles'))
Response from console:
C:\Users\myUser\Desktop\myFolder>node test.js
C:\Users\myUser\Desktop\myFolder\node_modules\css\lib\parse\index.js:130
css = css.slice(str.length);
^
TypeError: Object function prefix(style) {
function prefixSelector(selector){
var sel = selector
if (opts.namespaceBody !== false){
// Replace body with .body
sel = sel.replace(regBody, function(s){
return s.replace('body', '.body')
})
}
if (opts.namespaceHtml !== false){
// Replace html with .html
sel = sel.replace(regHtml, function(s){
return s.replace('html', '.html')
})
}
if (opts.selector){
var root = opts.root || 'html'
// TODO: This method would only replace the firs
t instance of root,
// so there is a rare bug when there are two cla
sses that both contain root.
// eg. if root is 'html' and an element has the
class .html5.html
// Add prefix to selector, adding it to the .htm
l part instead of prepending if needed
if (sel.indexOf(root) >= 0){
sel = sel.replace(root, root + opts.sele
ctor)
} else {
sel = opts.selector + ' ' + sel
}
}
return sel
}
function prefixClasses(selector){
return selector.split('.').join('.'+(opts.class || ''))
}
// Walk all styles
walk(style, function(rule, node) {
// Don't touch keyframes or font-face
if (!rule.selectors || rule.selectors.toString().indexOf
('@') >= 0)
return rule;
rule.selectors = rule.selectors.map(function(selector) {
return prefixSelector(prefixClasses(selector))
});
});
} has no method 'slice'
at match (C:\Users\myUser\Desktop\myFolder\node_modules\css\lib\parse\index.js:1
30:15)
at whitespace (C:\Users\myUser\Desktop\myFolder\node_modules\css\lib\parse\index
.js:139:5)
at rules (C:\Users\myUser\Desktop\myFolder\node_modules\css\lib\parse\index.js:1
09:5)
at stylesheet (C:\Users\myUser\Desktop\myFolder\node_modules\css\lib\parse\index
.js:81:16)
at module.exports (C:\Users\myUser\Desktop\myFolder\node_modules\css\lib\parse\i
ndex.js:559:20)
at rework (C:\Users\myUser\Desktop\myFolder\node_modules\rework\index.js:27:21)
at Object.<anonymous> (C:\Users\myUser\Desktop\myFolder\test.js:19:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
C:\Users\myUser\Desktop\myFolder>
Hi - I've been playing with this all afternoon and can't get it to work.
Repeatedly getting the following 🐛 error, any help appreciated:
[17:39:27] 'styles' errored after 961 μs Object function prefix(style) {
function prefixSelector(selector){
var sel = selector
console.log('node')
if (opts.namespaceBody !== false){
// Replace body with .body
sel = sel.replace(regBody, function(s){
return s.replace('body', '.body')
})
}
if (opts.namespaceHtml !== false){
// Replace html with .html
sel = sel.replace(regHtml, function(s){
return s.replace('html', '.html')
})
}
if (opts.selector){
var root = opts.root || 'html'
// TODO: This method would only replace the first instance of root,
// so there is a rare bug when there are two classes that both contain root.
// eg. if root is 'html' and an element has the class .html5.html
// Add prefix to selector, adding it to the .html part instead of prepending if needed
if (sel.indexOf(root) >= 0){
sel = sel.replace(root, root + opts.selector)
} else {
sel = opts.selector + ' ' + sel
}
}
return sel
}
function prefixClasses(selector){
return selector.split('.').join('.'+(opts.class || ''))
}
// Walk all styles
walk(style, function(rule, node) {
// Don't touch keyframes or font-face
if (!rule.selectors || rule.selectors.toString().indexOf('@') >= 0)
return rule;
rule.selectors = rule.selectors.map(function(selector) {
return prefixSelector(prefixClasses(selector))
});
});
} has no method 'slice'
Is there an example of usage without gulp? Seems like a really useful tool, but I don't want to bring any new build tools into my workflow if not required.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.