Giter Site home page Giter Site logo

webpack-content-replacer-plugin's Introduction


Webpack content replacer

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.

webpack-content-replacer-plugin's People

Contributors

dmukherjee avatar igitscor avatar nguyentk90 avatar yqbird avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

yqbird nguyentk90

webpack-content-replacer-plugin's Issues

Limit travis check

Hi,

We have to limit the travis checks, depending on the file type

  • MD => launch md linter (need to be instanciated)
  • .js => launch code coverage, js lint

Feel free to improve this list

CHANGELOG creation

Hi,

We have to create a changelog to persist changes and to had details for breaking changes.

Thanks

Rename plugin class

Hi,

According to Webpack team:

3rd party Plugin names should be foo-webpack-plugin for pkg name and FooWebpackPlugin for class

The package will not be renamed for now but we have to change plugin class.
It should keep compatibility with previous class name.

Task list

  • Change documentation
  • Update test case
  • Update class name

If you find another side effect, do not hesitate to correct it

Thank you

Test the done and failed steps

Hi,

Request a feature

What is the current behavior?

The current plugin is not tested in the webpack workflow for done and failed steps

What is the expected behavior?

The plugin can be launched at doneand failedstep

Thank you !

Testing in webpack workflow

Hello contributors,

The plugin is test covered as unit library.
We should add test in a webpack workflow.

Contribution

  • Creation of a demo webpack build (1 html file, 1 css file)
  • Use of this plugin
  • Test the webpack build (the plugin result)

OSS welcome resources

Hi folks,

This is an open source project, so it should be welcoming for all of us ! 🎉

Task list

Github template

  • Pull requests github template
  • Issues github template

Documentation

Github documentation

Project documentation

Improve documentation:

  • Installation
  • Contribution with more information about how to contribute and a section showing contributors

Add exception levels

Hi,

this plugin should have several exception levels

Exceptions

When an exception is caught, all the webpack build failed.
It should be nice if we could configure this behavior

Exception level

  • Strict: actual behavior. If the plugin fails, the webpack build crashes
  • None: no exception are caught and only a warning message is displayed in the console (if the silent mode is not activated)
  • Log: log errors in a log file (and also display a warning message like the none level)

Not forgive to add test

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.