Registry / devops / gulp-inject-string

gulp-inject-string

JSON →
library1.1.2jsnpmunverified

gulp-inject-string is a Gulp plugin designed to facilitate the injection and manipulation of string content within file streams during a build process. It provides a set of nine distinct methods, including `append`, `prepend`, `wrap`, `before`, `after`, `beforeEach`, `afterEach`, and `replace`, to programmatically modify the contents of files like HTML, JavaScript, or CSS as they pass through a Gulp pipeline. The current stable version is 1.1.2, released in January 2018. Development appears to be mature but largely inactive since then, indicating a stable but infrequently maintained state. Its primary differentiator is its straightforward, method-chaining API for precise string insertions and replacements, making it a utility for tasks like adding build timestamps, injecting script tags, or embedding environment-specific markers into source files during a build.

npm install gulp-inject-string
INSTALL
IMPORT
SIG · GULP-INJECT-STRING
G
gulp-inject-string
devopsjavascriptv1.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

inject
const inject = require('gulp-inject-string');
import inject from 'gulp-inject-string';
This package is a CommonJS module and does not natively support ES module `import` syntax. Attempting to use `import` might result in runtime errors in environments not configured for CJS-ESM interop.

This quickstart demonstrates how to use `gulp-inject-string` to replace a script filename in an HTML file with a minified and cache-busted version during a Gulp build process. It creates a dummy `src/example.html` and outputs a modified `build/index.html`.

const gulp = require('gulp'); const inject = require('gulp-inject-string'); const rename = require('gulp-rename'); const fs = require('fs'); const path = require('path'); // Task to prepare a dummy source file for the example gulp.task('prepare-src', function(done) { const srcDir = 'src'; if (!fs.existsSync(srcDir)) fs.mkdirSync(srcDir); const exampleHtmlPath = path.join(srcDir, 'example.html'); fs.writeFileSync(exampleHtmlPath, ` <!DOCTYPE html> <html> <head> <title>My Web App</title> </head> <body> <h1>Welcome!</h1> <p>This is a paragraph about the application.</p> <script src="app.js"></script> </body> </html> `); done(); // Signal task completion }); // Task to demonstrate replacing a string in the HTML file gulp.task('inject-replace-script-path', gulp.series('prepare-src', function() { const buildDir = 'build'; if (!fs.existsSync(buildDir)) fs.mkdirSync(buildDir); return gulp.src('src/example.html') .pipe(inject.replace('app.js', 'app.min.js?v=' + Date.now())) // Replace 'app.js' with a minified and cache-busted version .pipe(rename('index.html')) // Rename the output file to index.html .pipe(gulp.dest(buildDir)); // Save the modified file to the 'build' directory })); // Default task to run the example, utilizing gulp.series for sequential execution gulp.task('default', gulp.series('inject-replace-script-path', function(done) { console.log('Build complete. Check the ./build directory for index.html'); done(); }));
Debug
Known issues
gotchaThe package has not received significant updates since January 2018. While it remains functional for its core purpose, compatibility with very recent Node.js versions or highly specific Gulp 4+ stream configurations might require testing.
fix
Always test `gulp-inject-string` with your target Node.js and Gulp versions. Consider alternatives if frequent updates or advanced features are required.
affects: >=1.1.2
deprecatedThe example code in the official README uses `gulp.task('default', ['task1', 'task2'])` syntax for task dependencies, which is deprecated in Gulp 4. Users should adopt `gulp.series()` or `gulp.parallel()` for task composition.
fix
Migrate Gulp task composition to `gulp.series()` for sequential execution or `gulp.parallel()` for concurrent execution, e.g., `gulp.task('default', gulp.series('task1', 'task2'));`.
affects: >=1.0.0
gotchaThis package is exclusively a CommonJS module. Direct ES module `import` syntax will fail in Node.js environments unless explicitly configured for CJS-ESM interop (e.g., via a bundler or specific `package.json` configurations).
fix
Use `const inject = require('gulp-inject-string');` for all imports of this module within Node.js environments.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: inject.append is not a function
The `gulp-inject-string` module was imported incorrectly, or `inject` is not the expected object.
fix
Ensure you are using `const inject = require('gulp-inject-string');`. If using ES Modules, you might need a transpiler or a dynamic import for CommonJS modules, or to wrap the `require` call if the environment supports it.
The following tasks did not complete: default
A Gulp task (often the default one) failed to signal completion, commonly due to not returning a stream, promise, or calling a callback.
fix
Ensure your Gulp tasks return the stream (e.g., `return gulp.src(...).pipe(...)`), return a Promise, or explicitly call `done()` if a callback is passed to the task function.
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
gulp-inject-string — npm install gulp-inject-string · libregistry