Socket
Socket
Sign inDemoInstall

html-string-replace-webpack-plugin-webpack-4

Package Overview
Dependencies
324
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    html-string-replace-webpack-plugin-webpack-4

webpack html string replacement plugin


Version published
Weekly downloads
66
decreased by-27.47%
Maintainers
1
Install size
26.7 MB
Created
Weekly downloads
 

Readme

Source

HTML STRING REPLACE WEBPACK PLUGIN

npm version npm Inline docs contributions welcome

This is a webpack plugin that replace string in html files that created by html-webpack-plugin.
This is especially useful for adding some cdn prefix.

Installation

Install the plugin with npm:
$ npm install html-string-replace-webpack-plugin-webpack-4 --save-dev

Basic Usage

Add plugin to webpack config plugins. And pass options.

var HtmlStringReplace = require("html-string-replace-webpack-plugin-webpack-4");
var webpackConfig = {
  entry: "index.js",
  output: {
    path: "dist",
    filename: "index_bundle.js"
  },
  plugins: [
    new HtmlWebpackPlugin(),
    new HtmlStringReplace({
      enable: true,
      patterns: [
        {
          match: /href/g,
          replacement: function(match) {
            return match;
          }
        }
      ]
    })
  ]
};

Configuration

You can pass a hash of configuration options to HtmlStringReplace.
Allowed values are as follows:

  • enable: true | false whether enable this plugin or not.
  • patterns: add some patterns and how to replace the string.
  • patterns[parrern].replacement standard ECMAScript replace function or string

example:

new HtmlStringReplace({
  enable: true,
  patterns: [
    {
      // eg.
      // <link href="build.css">  =>
      // <link href="//cdn.baidu.com/static/build.css">
      match: /href=\"([^\"]*)\"/g,
      replacement: function(match, $1) {
        return 'href="' + CDN_PREFIX + $1 + '"';
      }
    },
    {
      // eg.
      // <script src="build.js">  =>
      // <script src="//cdn.baidu.com/static/build.js">
      match: /src=\"([^\"]*)\"/g,
      replacement: 'href="' + CDN_PREFIX + '$1"'
    }
  ]
});

Keywords

FAQs

Last updated on 28 Aug 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc