Giter Site home page Giter Site logo

rcorp / vulcanize Goto Github PK

View Code? Open in Web Editor NEW

This project forked from polymer/polymer-bundler

0.0 5.0 0.0 1.98 MB

Build tool for HTMLImports and Web Components

License: BSD 3-Clause "New" or "Revised" License

JavaScript 80.21% HTML 16.38% CSS 3.41%

vulcanize's Introduction

NPM version Build Status

Vulcanize

Reduce an HTML file and its dependent HTML Imports into one file

Named for the Vulcanization process that turns polymers into more durable materials.

Web pages that use multiple HTML Imports to load dependencies may end up making lots of network round-trips. In many cases, this can lead to long initial load times and unnecessary bandwidth usage. The Vulcanize tool follows HTML Imports and <script> tags to inline these external assets into a single page, to be used in production.

In the future, technologies such as HTTP/2 and Server Push will likely obsolete the need for a tool like vulcanize for production uses.

Installation

vulcanize is available on npm. For maximium utility, vulcanize should be installed globally.

npm install -g vulcanize

This will install vulcanize to /usr/local/bin/vulcanize (you may need sudo for this step).

Options

  • -h|--help: print this message
  • -v|--version: print version number
  • -p <arg>|--abspath <arg>: use as the "webserver root", make all adjusted urls absolute
  • --exclude <path>: exclude a subpath from root. Use multiple times to exclude multiple paths. Tags to excluded paths are kept.
  • --strip-exclude: Exclude a subpath and remove any links referencing it.
  • --inline-scripts: Inline external scripts.
  • --inline-css: Inline external stylesheets.
  • --strip-comments: Strips all HTML comments not containing an @license from the document.
  • --no-implicit-strip: DANGEROUS! Avoid stripping imports of the transitive dependencies of imports specified with --exclude. May result in duplicate javascript inlining.

Usage

The command

vulcanize target.html

will inline the HTML Imports of target.html and print the resulting HTML to standard output.

The command

vulcanize target.html > build.html

will inline the HTML Imports of target.html and print the result to build.html.

The command

vulcanize -p "path/to/target/" /target.html

will inline the HTML Imports of target.html, treat path/to/target/ as the webroot of target.html, and make all urls absolute to the provided webroot.

The command

vulcanize --exclude "path/to/target/subpath/" --exclude "path/to/target/subpath2/" target.html

will inline the HTML Imports of target.html that are not in the directory path/to/target/subpath nor path/to/target/subpath2.

If the --strip-exclude flag is used, the HTML Import <link> tags that point to resources in path/totarget/subpath and path/to/target/subpath2/ will also be removed.

The command

vulcanize --inline-scripts target.html

will inline scripts in target.html as well as HTML Imports. Exclude flags will apply to both Imports and Scripts.

The command

vulcanize --inline-css target.html

will inline Polymerized stylesheets, <link rel="import" type="css">

The command

vulcanize --strip-comments target.html

will remove HTML comments, except for those that begin with @license. License comments will be deduplicated.

Using vulcanize programmatically

Vulcanize as a library has two exported function.

vulcanize.setOptions takes an object of options similar to the command line options.

  • abspath: A folder to treat as "webroot".
    • When specified, use an absolute path to target.
  • excludes: An array of RegExp objects to exclude paths from being inlined.
  • stripExcludes: Similar to excludes, but strips the imports from the output entirely.
    • If stripExcludes is empty, it will be set the value of excludes by default.
  • inlineScripts: Inline external scripts.
  • inlineCss: Inline external stylesheets.
  • stripComments: Remove non-license HTML comments.
  • inputUrl: A URL string that will override the target argument to vulcanize.process(). By design, gulp and grunt plugins expect to work on the given file path. vulcanize has its own file loader, and expects to be given URLs. In instances where the filename cannot be used as a URL inputUrl will override the filename.
  • loader: A hydrolysis loader. This loader is generated with the target argument to vulcan.process and the exclude paths. A custom loader can be given if more advanced setups are necesssary.

vulcanize.process takes a target path to target.html and a callback.

Example:

var Vulcanize = require('vulcanize');
var hydrolysis = require('hydrolysis');

/* a Hydrolysis loader object (optional) */
var loader = new hydrolysis.loader(...)

var vulcan = new Vulcanize({
  abspath: '',
  excludes: [
  ],
  stripExcludes: [
  ],
  inlineScripts: false,
  inlineCss: false,
  implicitStrip: true,
  stripComments: false
  // optional
  loader: loader,
  inputUrl: ''
});

vulcan.process(target, function(err, inlinedHtml) {
});

What happened to [feature] from 0.X?

What about build tools

Analytics

vulcanize's People

Contributors

dfreedm avatar rush340 avatar garlicnation avatar pomax avatar tikicoder avatar ebidel avatar ragingwind avatar jklein24 avatar tbuckley avatar trevordixon avatar addyosmani avatar kevinpschaaf avatar lborgav avatar michaelfeinbier avatar tjsavage avatar

Watchers

James Cloos avatar  avatar Gaurav Ramanan avatar  avatar Jyoti Prakash avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.