{"id":13272,"library":"gulp-inject-string","title":"Gulp String Injection","description":"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.","status":"maintenance","version":"1.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/Schmicko/gulp-inject-string","tags":["javascript","gulpplugin","inject","insert","html","snippet"],"install":[{"cmd":"npm install gulp-inject-string","lang":"bash","label":"npm"},{"cmd":"yarn add gulp-inject-string","lang":"bash","label":"yarn"},{"cmd":"pnpm add gulp-inject-string","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import inject from 'gulp-inject-string';","symbol":"inject","correct":"const inject = require('gulp-inject-string');"}],"quickstart":{"code":"const gulp = require('gulp');\nconst inject = require('gulp-inject-string');\nconst rename = require('gulp-rename');\nconst fs = require('fs');\nconst path = require('path');\n\n// Task to prepare a dummy source file for the example\ngulp.task('prepare-src', function(done) {\n  const srcDir = 'src';\n  if (!fs.existsSync(srcDir)) fs.mkdirSync(srcDir);\n  const exampleHtmlPath = path.join(srcDir, 'example.html');\n  fs.writeFileSync(exampleHtmlPath, `\n<!DOCTYPE html>\n<html>\n<head>\n    <title>My Web App</title>\n</head>\n<body>\n    <h1>Welcome!</h1>\n    <p>This is a paragraph about the application.</p>\n    <script src=\"app.js\"></script>\n</body>\n</html>\n`);\n  done(); // Signal task completion\n});\n\n// Task to demonstrate replacing a string in the HTML file\ngulp.task('inject-replace-script-path', gulp.series('prepare-src', function() {\n    const buildDir = 'build';\n    if (!fs.existsSync(buildDir)) fs.mkdirSync(buildDir);\n\n    return gulp.src('src/example.html')\n        .pipe(inject.replace('app.js', 'app.min.js?v=' + Date.now())) // Replace 'app.js' with a minified and cache-busted version\n        .pipe(rename('index.html')) // Rename the output file to index.html\n        .pipe(gulp.dest(buildDir)); // Save the modified file to the 'build' directory\n}));\n\n// Default task to run the example, utilizing gulp.series for sequential execution\ngulp.task('default', gulp.series('inject-replace-script-path', function(done) {\n  console.log('Build complete. Check the ./build directory for index.html');\n  done();\n}));\n","lang":"javascript","description":"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`."},"warnings":[{"fix":"Always test `gulp-inject-string` with your target Node.js and Gulp versions. Consider alternatives if frequent updates or advanced features are required.","message":"The 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.","severity":"gotcha","affected_versions":">=1.1.2"},{"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'));`.","message":"The 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.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use `const inject = require('gulp-inject-string');` for all imports of this module within Node.js environments.","message":"This 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).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"The `gulp-inject-string` module was imported incorrectly, or `inject` is not the expected object.","error":"TypeError: inject.append is not a function"},{"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.","cause":"A Gulp task (often the default one) failed to signal completion, commonly due to not returning a stream, promise, or calling a callback.","error":"The following tasks did not complete: default"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}