babel-plugin-inject
v0.0.4
Published
Babel plugin for code injection
Downloads
19
Readme
babel-plugin-inject
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
- txt Simple plain text injection, used as a base for other content driven plugins
- html, html Placeholder for HTML injection. At this moment do nothing more then txt Could be extended to minify/optimize html
- tpl Compile HTML to Lodash completable template and provides temperating function
Helpers
- 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']
});