{"id":20458352,"url":"https://github.com/outatime/grunt-replace","last_synced_at":"2025-04-08T10:23:35.047Z","repository":{"id":3437197,"uuid":"4489561","full_name":"outaTiME/grunt-replace","owner":"outaTiME","description":"Replace text patterns with applause.","archived":false,"fork":false,"pushed_at":"2021-05-04T00:10:27.000Z","size":241,"stargazers_count":411,"open_issues_count":5,"forks_count":41,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-01T08:44:15.213Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/outaTiME.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-30T01:03:55.000Z","updated_at":"2024-04-19T11:06:24.000Z","dependencies_parsed_at":"2022-09-07T07:30:55.148Z","dependency_job_id":null,"html_url":"https://github.com/outaTiME/grunt-replace","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outaTiME%2Fgrunt-replace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outaTiME%2Fgrunt-replace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outaTiME%2Fgrunt-replace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outaTiME%2Fgrunt-replace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/outaTiME","download_url":"https://codeload.github.com/outaTiME/grunt-replace/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247820678,"owners_count":21001533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T12:12:06.231Z","updated_at":"2025-04-08T10:23:34.986Z","avatar_url":"https://github.com/outaTiME.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grunt-replace\n\n[![Build Status](https://img.shields.io/github/workflow/status/outaTiME/grunt-replace/CI)](https://github.com/outaTiME/grunt-replace/actions/workflows/main.yml)\n[![Version](https://img.shields.io/npm/v/grunt-replace.svg)](https://www.npmjs.com/package/grunt-replace)\n![Prerequisite](https://img.shields.io/badge/node-%3E%3D10-blue.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](#)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![Twitter: outa7iME](https://img.shields.io/twitter/follow/outa7iME.svg?style=social)](https://twitter.com/outa7iME)\n\n\u003e Replace text patterns with [applause](https://github.com/outaTiME/applause).\n\n## Install\n\nFrom NPM:\n\n```shell\nnpm install grunt-replace --save-dev\n```\n\n## Usage\n\nAssuming installation via NPM, you can use `grunt-replace` in your gruntfile like this:\n\n```javascript\nmodule.exports = function (grunt) {\n  grunt.initConfig({\n    replace: {\n      dist: {\n        options: {\n          patterns: [\n            {\n              match: 'foo',\n              replacement: 'bar'\n            }\n          ]\n        },\n        files: [\n          {\n            expand: true, flatten: true, src: ['src/index.html'], dest: 'build/'\n          }\n        ]\n      }\n    }\n  });\n  grunt.loadNpmTasks('grunt-replace');\n  grunt.registerTask('default', ['replace']);\n};\n```\n\n## Options\n\nSupports all the applause [options](https://github.com/outaTiME/applause#options) in addition to the ones below.\n\n### excludeBuiltins\nType: `Boolean`\nDefault: `false`\n\nIf set to `true`, the built-in matching rules are excluded.\n\n### force\nType: `Boolean`\nDefault: `true`\n\nForce the copy of files even when those files don't have any match found for replacement.\n\n### noProcess\nType: `String`\n\nThis option is an advanced way to control which file contents are processed.\n\n\u003e `processContentExclude` has been renamed to `noProcess` and the option name will be removed in the future.\n\n### encoding\nType: `String`\nDefault: `grunt.file.defaultEncoding`\n\nThe file encoding to copy files with.\n\n### mode\nType: `Boolean` or `Number`\nDefault: `false`\n\nWhether to copy or set the existing file permissions. Set to `true` to copy the existing file permissions. Or set to the mode, i.e.: `0644`, that copied files will be set to.\n\n### timestamp\nType: `Boolean`\nDefault: `false`\n\nWhether to preserve the timestamp attributes (atime and mtime) when copying files. Set to true to preserve files timestamp. But timestamp will not be preserved when the file contents or name are changed during copying.\n\n### silent\nType: `Boolean`\nDefault: `false`\n\nIf set to `true`, removes the output from stdout.\n\n### pedantic\nType: `Boolean`\nDefault: `false`\n\nIf set to `true`, the task will fail with a `grunt.fail.warn` when no matches are present.\n\n## Built-in replacements\n\nFew matching rules are provided by default and can be used anytime (these will be affected by the `options` given):\n\n *  `__SOURCE_FILE__`:\n\n    Replace match with the source file.\n\n *  `__SOURCE_PATH__`:\n\n    Replace match with the path of source file.\n\n *  `__SOURCE_FILENAME__`:\n\n    Replace match with the filename of source file.\n\n *  `__TARGET_FILE__`:\n\n    Replace match with the target file.\n\n *  `__TARGET_PATH__`:\n\n    Replace match with the path of target file.\n\n *  `__TARGET_FILENAME__`:\n\n    Replace match with the filename of target file.\n\n\u003e If you are looking how to use an `built-in` replacements, check out the [How to insert filename in target](#how-to-insert-filename-in-target) usage.\n\n## Examples\n\n### Basic\n\nFile `src/manifest.appcache`:\n\n```\nCACHE MANIFEST\n# @@timestamp\n\nCACHE:\n\nfavicon.ico\nindex.html\n\nNETWORK:\n*\n```\n\nTask configuration on gruntfile:\n\n```javascript\n{\n  options: {\n    patterns: [\n      {\n        match: 'timestamp',\n        replacement: '\u003c%= Date.now() %\u003e'\n      }\n    ]\n  },\n  files: [\n    {\n      expand: true, flatten: true, src: ['src/manifest.appcache'], dest: 'build/'\n    }\n  ]\n}\n```\n\n### Multiple matching\n\nFile `src/manifest.appcache`:\n\n```\nCACHE MANIFEST\n# @@timestamp\n\nCACHE:\n\nfavicon.ico\nindex.html\n\nNETWORK:\n*\n```\n\nFile `src/humans.txt`:\n\n```\n              __     _\n   _    _/__  /./|,//_`\n  /_//_// /_|///  //_, outaTiME v.@@version\n\n/* TEAM */\n  Web Developer / Graphic Designer: Ariel Oscar Falduto\n  Site: https://www.outa.im\n  Twitter: @outa7iME\n  Contact: afalduto at gmail dot com\n  From: Buenos Aires, Argentina\n\n/* SITE */\n  Last update: @@timestamp\n  Standards: HTML5, CSS3, robotstxt.org, humanstxt.org\n  Components: H5BP, Modernizr, jQuery, Bootstrap, LESS, Jade, Grunt\n  Software: Sublime Text, Photoshop, LiveReload\n```\n\nTask configuration on gruntfile:\n\n```javascript\n{\n  options: {\n    patterns: [\n      {\n        match: 'version',\n        replacement: '\u003c%= pkg.version %\u003e'\n      },\n      {\n        match: 'timestamp',\n        replacement: '\u003c%= Date.now() %\u003e'\n      }\n    ]\n  },\n  files: [\n    {\n      expand: true, flatten: true, src: ['src/manifest.appcache', 'src/humans.txt'], dest: 'build/'\n    }\n  ]\n}\n```\n\n### Cache busting\n\nFile `src/index.html`:\n\n```html\n\u003chead\u003e\n  \u003clink rel=\"stylesheet\" href=\"/css/style.css?rel=@@timestamp\"\u003e\n  \u003cscript src=\"/js/app.js?rel=@@timestamp\"\u003e\u003c/script\u003e\n\u003c/head\u003e\n```\n\nTask configuration on gruntfile:\n\n```javascript\n{\n  options: {\n    patterns: [\n      {\n        match: 'timestamp',\n        replacement: '\u003c%= Date.now() %\u003e'\n      }\n    ]\n  },\n  files: [\n    {\n      src: ['src/index.html'], dest: 'build/index.html'\n    }\n  ]\n}\n```\n\n### Include file\n\nFile `src/index.html`:\n\n```html\n\u003cbody\u003e\n  @@include\n\u003c/body\u003e\n```\n\nTask configuration on gruntfile:\n\n```javascript\n{\n  options: {\n    patterns: [\n      {\n        match: 'include',\n        replacement: '\u003c%= grunt.file.read(\"includes/content.html\") %\u003e'\n      }\n    ]\n  },\n  files: [\n    {\n      expand: true, flatten: true, src: ['src/index.html'], dest: 'build/'\n    }\n  ]\n}\n```\n\n### Regular expression\n\nFile `src/username.txt`:\n\n```\nJohn Smith\n```\n\nTask configuration on gruntfile:\n\n```javascript\n{\n  options: {\n    patterns: [\n      {\n        match: /(\\w+)\\s(\\w+)/,\n        replacement: '$2, $1' // Replaces \"John Smith\" with \"Smith, John\"\n      }\n    ]\n  },\n  files: [\n    {\n      expand: true, flatten: true, src: ['src/username.txt'], dest: 'build/'\n    }\n  ]\n}\n```\n\n### Lookup for `foo` instead of `@@foo`\n\nTask configuration on gruntfile:\n\n```javascript\n{\n  'opt-1': {\n    options: {\n      patterns: [\n        {\n          match: /foo/g, // Explicitly using a regexp\n          replacement: 'bar'\n        }\n      ]\n    },\n    files: [\n      {\n        expand: true, flatten: true, src: ['src/foo.txt'], dest: 'build/'\n      }\n    ]\n  },\n  'opt-2': {\n    options: {\n      patterns: [\n        {\n          match: 'foo',\n          replacement: 'bar'\n        }\n      ],\n      usePrefix: false // Using the option provided\n    },\n    files: [\n      {\n        expand: true, flatten: true, src: ['src/foo.txt'], dest: 'build/'\n      }\n    ]\n  },\n  'opt-3': {\n    options: {\n      patterns: [\n        {\n          match: 'foo',\n          replacement: 'bar'\n        }\n      ],\n      prefix: '' // Removing the prefix manually\n    },\n    files: [\n      {\n        expand: true, flatten: true, src: ['src/foo.txt'], dest: 'build/'\n      }\n    ]\n  }\n}\n```\n\n### How to insert filename in target\n\nFile `src/app.js`:\n\n```javascript\n// Filename: @@__SOURCE_FILENAME__\n\nvar App = App || (function () {\n  return {\n    // App contents\n  };\n})();\n\nwindow.App = App;\n```\n\nTask configuration on gruntfile:\n\n```javascript\n{\n  options: {\n    // Pass, we use built-in replacements\n  },\n  files: [\n    {\n      expand: true, flatten: true, src: ['src/**/*.js'], dest: 'build/'\n    }\n  ]\n}\n```\n\n## Related\n\n- [applause](https://github.com/outaTiME/applause) - Human-friendly replacements\n\n## License\n\nMIT © [outaTiME](https://outa.im)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foutatime%2Fgrunt-replace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foutatime%2Fgrunt-replace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foutatime%2Fgrunt-replace/lists"}