gulp-source-injector
Injects any source into any file.
Table of Contents
Description
gulp-source-injector
transforms content of each source file to a string and injects each transformed string into placeholders in the target stream files.
This plugin does not do any minification to source files, so whitespaces will be preserved. It's better to use it after transformations like gulp-terser
or gulp-clean-css
.
Install
npm install --save-dev gulp-source-injector
Usage
Injection placeholders are comments as html syntax <!-- inject: filePath -->
and css/js syntax /* inject: filePath */
By default the injected file path is relative to each target file's cwd
. If the provided path starts with /
, it will be considered relative to the directory of gulpfile.js
Example
Project structure
├── src│ ├── css│ │ └── style.css│ ├── js│ │ └── script.js│ ├── template│ │ └── head.html│ └── index.html└── gulpfile.js
Target file src/index.html
<!-- inject: /src/template/head.html --> Lorem Ipsum
gulpfile.js
const task src dest = const inject =
or you can
and then
dist/index.html
after running gulp inject
Lorem Ipsum
Indentation
Note that existing indentation won't be preserved.
Target file src/index.html
Lorem Ipsum
Source file src/css/style.css
dist/index.html
Lorem Ipsum