To avoid this, see the advanced example below.Įxamples Multiple files and multiple replacements 'string-replace': Advanced inlineSince grunt-string-replace is basically a wrapper of you can also provide a function as a replacement pattern instead of a string or a template as a nice added bonus to using a replacement function, grunt-string-replace will provide 2 extra arguments apart from the ones documented in the link below: src and dest. When using Grunt templates, be aware that some security checks are implemented by LoDash and may alter your content (mainly to avoid XSS).If the pattern is a string, only the first occurrence will be replaced, as stated on.A pattern/replacement pair should contain key:value pairs containing: options.replacements arrayThis option will hold all your pattern/replacement pairs. This will speed up the task if there is a large number of files. options.saveUnchanged booleanBy default true this flag will instruct grunt-string-replace to copy the files on options.replacements patterns even if there are no replacing matches.īy setting this flag to false files that have not changed (no replacements done) will not be saved on the new location. options objectControls how this task operates and should contain key:value pairs, see options below. Learn more at Gruntfile Files mapping, some options incude compact format, files object format and files array format. Grunt itself has very powerful abstractions, so it is highly recommended you understand the different ways to specify them. Parameters files objectDefines what files this task will edit. This section specifies the files to edit, destinations, patterns and replacements. ConfigurationInside your Gruntfile.js file add a section named string-replace. If you're still using grunt v0.3.x it's strongly recommended that you upgrade, but in case you can't please use v0.1.1-1. Grunt.loadNpmTasks("grunt-string-replace") Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: Npm install grunt-string-replace -save-dev Once you're familiar with that process, you may install this plugin with this command: If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Getting StartedThis plugin requires node >= 0.10.0, Grunt >= 0.4.0 and npm >= 1.4.15 (latest stable is recommended). Attempts to be a adapter task for your grunt project. (not yet compatible with optimizeChunkAssets) rules.X.replacements.X.Grunt-string-replace Replaces strings on files by using string or regex patterns. > If set, locations where patterns are matched will have X characters of the source code (before and after) logged for inspection. > Examples: (see rules.X.chunkMatchCount) logAroundPatternMatches - number (condition must be met for at least one compilation) > Checked against the number of pattern matches, in all (unignored) chunks/files within the compilation. Installation npm install -save-dev webpack-string-replacerīasic example: const WebpackStringReplacer = require("webpack-string-replacer") Replace strings in webpack modules, with configurable apply-stage and match-count requirements.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |