Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

raw-edit-loader

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raw-edit-loader

A loader for webpack, support modify source string. Through the configuration of a series of properties, to modify the matching string

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

raw-edit-loader

view on npm npm module downloads per month

A loader for webpack, support modify source string. Through the configuration of a series of properties, to modify the matching string.

usage

npm i -D raw-edit-loader

General configuration:

// src/index.js
console.log('Hello world!')
// webpack.config.js
{
  test: /\.js$/,
  use: ['babel-loader', {
    loader: 'raw-edit-loader',
    options: {
      // pathList: [path.resolve(__dirname, './src/index.js')],
      pathReg: /src\/index.js/,
      replaceReg: /Hello/,
      replacement: 'Hi, ',
      done: function(source) {
        return source
      },
    }
  }],
}

Before passing in the next loader, the source will be modified to:

// source string
console.log('Hi, wold!')

or group matching:

// webpack.config.js
{
  test: /\.js$/,
  use: ['babel-loader', {
    loader: 'raw-edit-loader',
    options: {
      group: [
        {
          pathReg: /src\/index.js/,
          replaceReg: /Hello/,
          replacement: 'Hi, ',
          done: function(source) {
            return source
          },
        }
      ]
    }
  }],
}

options

pathList [array]

Matching file absolute path list. If pathReg configured, the property will be invalid.

{
  pathList: ['/path/to/index.js', '/path/to/b.js']
}
pathReg [RegExp]

Matching file path regular expression. If pathList configured, the property will be invalid.

{
  pathReg: /src\/index.js/,
}
replaceReg [RegExp]

Match the source string regular expression and the hit fragment will be replaced.

{
  replaceReg: /Hello/,
}
replacement [string | Function]

Match the source string regular expression and the hit fragment will be replaced. string.replace(replaceReg, replacement)

{
  replacement: 'Hi, ',
}
group [array]

If the matching group is configured, the single mode property will be invalid

{
  group: [
    {
      pathReg: /src\/index.js/,
      replaceReg: /Hello/,
      replacement: 'Hi, ',
      done: function(source) {
        return source
      },
    },
    {
      pathReg: /src\/a.js/,
      replaceReg: /May/,
      replacement: 'Can',
      done: function(source) {
        return source
      },
    }
  ]
}
done [Function]

After the source operation is completed, the done method is called. Need return source.

{
  done: function(source) {
    return `${source};console.log('hello world')`
  },
}

Keywords

FAQs

Package last updated on 09 Apr 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc