1. string-replace-webpack-plugin
Replace string tokens in the contents of a file.
string-replace-webpack-plugin
Package: string-replace-webpack-plugin
Created by: jamesandersen
Last modified: Mon, 27 Jun 2022 01:02:58 GMT
Version: 0.1.3
License: MIT
Downloads: 83,459
Repository: https://github.com/jamesandersen/string-replace-webpack-plugin

Install

npm install string-replace-webpack-plugin
yarn add string-replace-webpack-plugin

string replace plugin for webpack

Usage example

 var StringReplacePlugin = require("string-replace-webpack-plugin");
module.exports = {
   module: {
      loaders: [
         // configure replacements for file patterns
         { 
            test: /index.html$/,
            loader: StringReplacePlugin.replace({
                replacements: [
                    {
                        pattern: /<!-- @secret (\w*?) -->/ig,
                        replacement: function (match, p1, offset, string) {
                            return secrets.web[p1];
                        }
                    }
                ]})
            }
      ]
   },
   plugins: [
      // an instance of the plugin must be present
      new StringReplacePlugin()
   ]
}

This allows for arbitrary strings to be replaced as part of the module build process. The original intent is to replace API
keys in modules prior to deployment.

API

 StringReplacePlugin.replace([nextLoaders: string], options, [prevLoaders: string])
  • nextLoaders loaders to follow the replacement
  • options
    • replacements disables the plugin
  • prevLoaders loaders to apply prior to the replacement

License

MIT (http://www.opensource.org/licenses/mit-license.php)

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin