Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
forked fromuncss/uncss

Remove unused styles from CSS

License

NotificationsYou must be signed in to change notification settings

javifelices/uncss

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusCoverage StatusDependency StatusdevDependency Status

UnCSS is a tool that removes unused CSS from your stylesheets.It works across multiple files and supports Javascript-injected CSS.

How?

The process by which UnCSS removes the unused rules is as follows:

  1. The HTML files are loaded byPhantomJS and JavaScript is executed.
  2. Used stylesheets are extracted from the resulting HTML.
  3. The stylesheets are concatenated and the rules are parsed bycss-parse.
  4. document.querySelector filters out selectors that are not found in the HTML files.
  5. The remaining rules are converted back to CSS.

Installation:

npm install -g uncss

Usage

Within Node.js:

varuncss=require('uncss');varfiles=['my','array','of','HTML','files','or','http://urls.com'],options={ignore       :['#added_at_runtime',/test\-[0-9]+/],media        :['(min-width: 700px) handheld and (orientation: landscape)'],csspath      :'../public/css/',raw          :'h1 { color: green }',stylesheets  :['lib/bootstrap/dist/css/bootstrap.css','src/public/css/main.css'],ignoreSheets :[/fonts.googleapis/],timeout      :1000,htmlroot     :'public',report       :false};uncss(files,options,function(error,output){console.log(output);});/* Look Ma, no options! */uncss(files,function(error,output){console.log(output);});/* Specifying raw HTML */varraw_html='...';uncss(raw_html,options,function(error,output){console.log(output);});

At build-time

UnCSS can also be used in conjunction with other javascript build systems, such asGrunt orGulp!Thanks to @addyosmani for creating:

and to @ben-eb for creating:

From the command line:

Usage: uncss [options] <file or url, ...>       e.g. uncss http://getbootstrap.com/examples/jumbotron/ > stylesheet.cssOptions:  -h, --help                            output usage information  -V, --version                         output the version number  -i, --ignore <selector, ...>          Do not remove given selectors  -m, --media <media_query, ...>        Process additional media queries  -C, --csspath <path>                  Relative path where the CSS files are located  -s, --stylesheets <file, ...>         Specify additional stylesheets to process  -S, --ignoreSheets <selector, ...>    Do not include specified stylesheets  -r, --raw <string>                    Pass in a raw string of CSS  -t, --timeout <milliseconds>          Wait for JS evaluation  -H, --htmlroot <folder>               Absolute paths' root location

Note that you can pass both local file paths and URLs to the program.

  • ignore (Array): provide a list of selectors that should not be removed by UnCSS. For example, styles added by user interaction with the page (hover, click), since those are not detectable by UnCSS yet. Both literal names and regex patterns are recognized. Otherwise, you can add common in CSS file like:
/* uncss:ignore */.selector1 {/* this rule will be ignored */}.selector2 {/* will NOT */}
  • media (Array): By default UnCSS processes only stylesheets with media query "all", "screen", and those without one. Specify here which others to include.

  • csspath (String): path where the CSS files are related to the html files. By default, UnCSS uses the path specified in the<link rel="stylesheet" href="path/to/file.css"/>

  • stylesheets (Array): use these stylesheets instead of those extracted from the html files.

  • ignoreSheets (Array): do not process these stylesheets, e.g. Google fonts. Accepts strings or regex patterns

  • raw (String): give the task a raw string of CSS in addition to the existing stylesheet options; useful in scripting when your CSS hasn't yet been written to disk.

  • timeout (Number): specify how long to wait for the JS to be loaded.

  • htmlroot (String): Where the project root is. Useful for example if you are running UnCSS onlocal files that have absolute href to the stylesheets, i.e.href="/css/style.css"

  • report (Boolean): return the report object in callback

License

Copyright (c) 2013 Giacomo Martino. See theLICENSE file for license rights and limitations (MIT).

About

Remove unused styles from CSS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript61.5%
  • CSS38.5%

[8]ページ先頭

©2009-2025 Movatter.jp