JSPM

  • Created
  • Published
  • Downloads 16744
  • Score
    100M100P100Q132468F
  • License MIT

Inline all flagged js & css source files

Package Exports

  • inline-source

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (inline-source) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build Status

inline-source

Inline and compress all <script> or <link> tags that contain the inline attribute.

Usage

NOTE: If an error is encoutered when inlining a tag, the inline attribute will be removed and the remaining tag contents will be left untouched unless options.swallowErrors = false.

<!-- project/src/html/index.html -->
<!DOCTYPE html>
<html>
<head>
  <!-- inline project/src/js/inlineScript.js -->
  <script inline src="../js/inlineScript.js"></script>
  <!-- inline project/scripts/inlineScript.js -->
  <script inline src="/scripts/inlineScript.js"></script>
  <!-- inline project/src/css/inlineStyle.css -->
  <link inline rel="../css/inlineStyle.css"></link>
</head>
</html>
var inline = require('inline-source')
  , fs = require('fs')
  , path = require('path')
  , htmlpath = path.resolve('project/src/html/index.html');
  , html = fs.readFileSync(htmlpath, 'utf8');

html = inline(htmlpath, html, {compress: true, swallowErrors: true});