0.0.2 • Published 4 years ago

rewrite-source-webpack-plugin v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Webpack Plugin to rewrite the source before compilation. Files will be restored to their original state after compilation.

Why?

You may want to alter the source code before compilation. (E.g. if you have templated variables.)

Install

npm i -D rewrite-source-webpack-plugin

Usage

In your webpack.config.json, you can rewrite source files either by path or a regular expression:

  plugins: [
    ...
    new RewriteSourcePlugin([
      {
        test: /src\/App.js/,
        rewrite: (src) => {
          return src.replace(/{{foo}}/g, 'A template variable');
        }
      },
      {
        path: './src/index.html',
        rewrite: (src) => {
          return src.replace(/{{title}}/g, 'My page title');
        }
      },
      {
        path: './src/index.html',
        rewrite: (src) => {
          return src.replace(/{{description}}/g, 'My page description');
        }
      },
    ]),
    new HtmlWebPackPlugin({
      template: "./src/index.html",
      filename: "./index.html"
    }),
  ],