EsifyCSS

Generates modules from CSS.
Assume you have style.css
below.

Then, run the esifycss
command.

You'll get style.css.js
(and helper.js
).

You can import the generated script from
It exports className
, id
, and keyframes
that are shortened uniquely.
The uniqueness makes styles modular. This means you don't have to concern about
naming somethings in CSS.
Each string given to addStyle
represents a CSS string.
They are inserted to the document's stylesheet by the helper script.
EsifyCSS consists of a PostCSS plugin and a Runner.
PostCSS plugin
The plugin converts the identifiers in CSS and minifies them.
It outputs the result of minifications using Root.warn().
Runner
A runner process .css
files in your project with PostCSS and output the
results to .css.js
or .css.ts
.
Installation
npm install --save-dev esifycss
Usage
Usage: esifycss [options] <include ...>
Options:
-V, --version output the version number
--helper <path> A path to the helper script.
--config <path> A path to configuration files.
--exclude <path ...> Paths or patterns to be excluded.
--noMangle Keep the original name for debugging.
--watch Watch files and update the modules automatically.
-h, --help output usage information
@import
Syntax
You can use @import
syntax when the style declarations requires names in external files.
Example: Assume you have the following a.css
and b.css
.
.container {...}
.container {...}
The container
class names will be shortened to unique names like
_0
and _1
.
You can import the shortened names with the @import
syntax.
@import './a.css' modA-;
@import './b.css' BBB;
.wrapper>.modA-container {...}
.wrapper>.BBBcontainer {...}
JavaScript API for Runner
import {Session} from 'esifycss';
new Session(options).start()
.then(() => console.log('Done'))
.catch((error) => console.error(error));
Options
export interface ISessionOptions {
include?: string | Array<string>,
exclude?: anymatch.Matcher,
helper?: string,
watch?: boolean,
chokidar?: chokidar.WatchOptions,
postcssPlugins?: Array<postcss.AcceptedPlugin>,
esifycssPluginParameter?: IPluginOptions,
stdout?: stream.Writable,
stderr?: stream.Writable,
}
Source: src/runner/types.ts
JavaScript API for Plugin
const postcss = require('postcss');
const esifycss = require('esifycss');
postcss([
esifycss.plugin({}),
])
.process(css, {from: '/foo/bar.css'})
.then((result) => {
const pluginResult = esifycss.extractPluginResult(result);
console.log(pluginResult);
});
The code is at sample/plugin.js.
You can run it by node sample/plugin.js
after cloning this repository and
running npm run build
.
Options
export interface IPluginOptions {
mangle?: boolean,
identifier?: IIdentifier,
rawPrefix?: string,
mangler?: IPluginMangler,
}
Source: src/postcssPlugin/types.ts
LICENSE
The esifycss project is licensed under the terms of the Apache 2.0 License.