Skip to content

tugboatcoding/rewrite-source-webpack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rewrite-source-webpack-plugin

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"
    }),
  ],

About

Webpack Plugin to rewrite the source before compilation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published