Apply css text into browser's style tag, can work with cssobj-plugin-gencss.
var cssobj_core = require('cssobj-core')
var gencss = require('cssobj-plugin-gencss')
var stylize = require('cssobj-helper-stylize')
var cssobj = cssobj_core({
plugins: [gencss()],
onUpdate: stylize({id: 'mycss'})
})
cssobj(obj)
// generated css text will be insert into <head>
npm install cssobj/cssobj-helper-stylize
Return a function accept result
and insert result.css
into <style>
tag.
-
id
: {string} The id for<style>
tag, if omit, will using random string. -
attrs
: {object} The key/val to apply to<style>
tag as attributes.
A function can be used in cssobj onUpdate
option.
// in cssobj({ onUpdate:.... })
onUpdate: stylize({name:'index-page-style'})
onUpdate: stylize({name:'index-page-style', attrs:{type:'text/css', media:'screen'} })
This helper take simplicy first, just update all css text into <style>
tag, may have performance issues.
plugin-cssom take effiency first, it create every css rule and patch rules with result.diff
If you want apply cssobj once, and don't update result frequently, use plugin-gencss
+ helper-stylize
If you want update result frequently, use plugin-cssom
, it optimized for this type of usage.