hexojs / hexo-asset-pipeline

A hexo plugin to minify/optimize HTML, CSS, JS and images. Supports revisioning of assets.
29 stars 16 forks source link
assets clean-css css hexo hexo-asset-pipeline hexo-plugin html-minifier imagemin javascript optimization revisioning stylesheets uglifyjs

DEPRECATED!

hexo-asset-pipeline has been deprecated.

hexo-asset-pipeline

Dependency Status npm version GitHub issues

Asset pipeline for Hexo to support minification and optimization of HTML, CSS, JS and images.

Installation

$ npm install hexo-asset-pipeline --save

Configuration

Add the following snippet in _config.yml.

Minimal config to enable filters for HTML, CSS, Js and images.

asset_pipeline:
  revisioning:
    enable: true
  clean_css:
    enable: true
  uglify_js:
    enable: true
  imagemin:
    enable: true
  html_minifier:
    enable: true

Components

Following are the modules that are being used to process differnet types of assets.

HTML (html_minifier)

html-minifier is used to minify the HTML files.

Following is the config for html-minifier.

Options

html_minifier:
  enable: true
  ignore_error: false
  exclude:

html_minifier defaults

html_minifier:
  ignoreCustomComments: [/^\s*more/]
  removeComments: true
  removeCommentsFromCDATA: true
  collapseWhitespace: true
  collapseBooleanAttributes: true
  removeEmptyAttributes: true
  minifyJS: true
  minifyCSS: true

Note: Check html-minifier for more options.

Javascripts (uglify_js)

uglify-js is used to minify javascripts.

Following is the config for uglify-js.

Options

uglify_js:
  enable: true
  mangle: true
  output:
  compress:
  exclude: 
    - '*.min.js'

uglify-js defaults

uglify_js:
  mangle: true
  exclude: ['*.min.js']

Note: Check uglify-js for more options.

Stylesheets (clean_css)

clean-css is used to minify stylesheets.

Following is the config for clean-css.

Options

clean_css:
  enable: true
  exclude: 
    - '*.min.css'

clean-css defaults

clean_css:
  exclude: ['*.min.css']

Note: Check clean-css for more options.

Images (imagemin)

imagemin is used to optimize images.

Following is the config for imagemin.

Options

imagemin:
  enable: true
  interlaced: false
  multipass: false
  optimizationLevel: 2
  pngquant: false
  progressive: false

imagemin defaults

imagemin:
  interlaced: false
  multipass: false
  optimizationLevel: 3
  pngquant: false
  progressive: false

Note: Check imagemin plugins for more options.

Revisioning

revisioning:
  enable: true
  keep: true
  exclude: ['robots.txt', '*.json']
  selectors:
    'img[data-orign]':  data-orign
    'img[data-src]': 'data-src'
    'img[src]': 'src'

Revisioning defaults;

revisioning:
  enable: false
  keep: false
  exclude: []
  selectors:
    'img[data-src]': 'data-src'
    'img[src]': 'src'
    'link[rel="apple-touch-icon"]': 'href'
    'link[rel="icon"]': 'href'
    'link[rel="shortcut icon"]': 'href'
    'link[rel="stylesheet"]': 'href'
    'script[src]': 'src'
    'source[src]': 'src'
    'video[poster]': 'poster'

Note: To match paths in exclude option, glob matching is done using micromatch.

TODO