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

raw-edit-loader

v0.2.0

Published

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

Downloads

4

Readme

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')`
  },
}