Easy asset injection with NPM.
npm i assetinjector --save-dev
attributes
(object) - Add attributes to<link>
or<script>
tagsbasePaths
(array) - List of folders with files inside to inject into the source fileomit
(string) - A string to omit from the reference in the injection (useful if you output to a separate folder from assets)source
(string) - The source file that you want to inject into
attributes: {
'css': {
rel: 'stylesheet',
type: 'text/css'
},
'js': null
},
basePaths: [],
omit: '',
source: ''
Edit your source file to contain comments where you'd like to inject these files, and the semantic type should match the file extension you want to inject. For example:
To inject CSS:
<!--inject:css-->
<!--inject:stop-->
To inject JS:
<!--inject:js-->
<!--inject:stop-->
And then appropriate elements will be added between the comments.
Currently the module has support for JS and CSS files, but please request another if you'd like more.
var injector = require('assetinjector');
injector({source: './public/header.html', basePaths: ['./public/_css', './public/_js'], omit: './public'});
Coming soon.