0.0.4 • Published 8 years ago

babel-plugin-inject v0.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

babel-plugin-inject Build Statuscodecov.io

Proposal

Plugin is useful in any case that requires to provide external asset or resource (mostly like css, html or txt files) to be used in your code. Any embedding task like building standalone pages, email newsletters or injectable widgets for the page.

Usage Example

import Widget from './widgetClass.js';


(function (template1Html, template2Html, style1Css, style2Css) {

  class Widget1 extends Widget {

    constructor(options) {
      super(options);
    }

    method1() {

    }
  }


  var w = new Widget1();

  w.method1();


})(
  inject('./static1.htm'),
  inject('./template2.tpl'),  // To be preprocessed
  inject('./style1.css'),
  inject('./style2.sass') // To be preprocessed
);
let injectCss = inject('injectCSS');
injectCSS('body{color:red}');

Plugins

  1. txt Simple plain text injection, used as a base for other content driven plugins
  2. html, html Placeholder for HTML injection. At this moment do nothing more then txt Could be extended to minify/optimize html
  3. tpl Compile HTML to Lodash completable template and provides temperating function

Helpers

  1. injectCSS inserts provided CSS to document

Installation

$ npm install babel-plugin-inject --save

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["babel-plugin-inject"]
}

Via CLI

$ babel --plugins babel-plugin-inject script.js

Via Node API

require("babel-core").transform('source code', {
  plugins: ['babel-plugin-inject']
});