npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webpack-content-replacer-plugin

v0.5.1

Published

Replace content in file in webpack workflow

Downloads

48

Readme

Build Status codecov Node dependency Dependencies dependencies Status devDependencies Status MIT License

Replace content in file in webpack workflow

Edit file by replacing content at different build step in a webpack workflow.

For example, you can change text color, text content or also insert configuration values from environment variables.

Installing

npm i webpack-content-replacer-plugin

Getting started in webpack

Require webpack-content-replacer-plugin

var ContentReplacerWebpackPlugin = require('webpack-content-replacer-plugin')

Add the plugin to your plugin list

var config = {
  plugins: [
    new ContentReplacerWebpackPlugin({
      modifiedFile: './relative_path/file_to_be_modified.ext',
      modifications: [
        {
          regex: /%content_to_be_deleted%/g,
          modification: 'new_content',
        },
        {
          regex: /%content2_to_be_deleted%/g,
          modification: 'new_content2',
        },
      ],
    })
  ]
}

Configuration

modifiedFile

  • Type: String
  • Default: no default value
  • Required: true

Specify the file which will be modified.

Example:

var config = {
  plugins: [
    new ContentReplacerWebpackPlugin({
      modifiedFile: './build/index.html',
      ...
    })
  ]
}

modifications

  • Type: Array<Modification>
  • Default: no default value
  • Required: true

Specify the modifications to be applied to the file.

Example:

var config = {
  plugins: [
    new ContentReplacerWebpackPlugin({
      modifiedFile: './build/index.html',
      [
        {
          regex: /text/g,
          modification: 'new text'
        }
      ],
      ...
    })
  ]
}
modification
  • Type: Object
  • Default: no default value
  • Required: true

Example:

{
  regex: /text/g,
  modification: 'new text'
}

buildTrigger

  • Type: String
  • Default: after-emit
  • Allowed values: after-emit, done

Specify webpack build step (c.f plugin documentation).

Example:

var config = {
  plugins: [
    new ContentReplacerWebpackPlugin({
      modifiedFile: './build/index.html',
      [
        {
          regex: /text/g,
          modification: 'new text'
        }
      ],
      buildTrigger: 'done',
      ...
    })
  ]
}

logLevel

  • Type: String
  • Default: strict
  • Allowed value: strict, log, none
    • strict: catch errors in an exception, the webpack build crashes
    • log: log errors in a log file (warning.log) and none behavior
    • none: show errors in console (when silent mode is off)

Specify behavior when the plugin fail.

Example:

var config = {
  plugins: [
    new ContentReplacerWebpackPlugin({
      modifiedFile: './build/index.html',
      [
        {
          regex: /text/g,
          modification: 'new text'
        }
      ],
      buildTrigger: 'done',
      logLevel: 'log'
      ...
    })
  ]
}

silent

  • Type: Boolean
  • Default: false

Display/hide info logs during the build.

Example:

var config = {
  plugins: [
    new ContentReplacerWebpackPlugin({
      silent: true,
      modifiedFile: './build/index.html',
      [
        {
          regex: /text/g,
          modification: 'new text'
        }
      ],
      buildTrigger: 'done'
      ],
    })
  ]
}

Developing

git clone https://github.com/{your fork}/webpack-content-replacer-plugin.git
cd webpack-content-replacer-plugin/
npm install

Replace {your fork} by your github username.

Contributing

If you'd like to contribute, please fork the repository and use a feature branch. All contributions are welcome. Please make a pull request and make sure things still pass after running npm test. Ensure you've read the contribution guidelines for more information and respect the code of conduct

Contributors

Thanks goes to these wonderful people (emoji key):

| Sebastien Correaud🚇 💻 📖 ⚠️ 👀 | YQBird📖 ⚠️ 👀 | | :---: | :---: |

This project follows the all-contributors specification. Contributions of any kind welcome!

Licensing

The code in this project is licensed under MIT license.