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

replace-daddy

v2.1.2

Published

Replace everything in all plain text file

Downloads

6

Readme

Replace loader for Webpack

Replace everything in all plain text file...

Install:

$ npm i -D replace-daddy

Usage:

Hardcode


# project
const assetsPath = '__debug__'==='true' ? `http://__localIP__:__localPORT__/foo` : `//cdn.site.com/assets/bar`;
import routes from './router/__routerMode__'
/* webpackChunkName: "__spaDirBuild__/Index" */

# webpack
module.exports = {
  // ...
  module: {
    loaders: [
      {
        exclude: /node_modules/,
        test: /\.(js|jsx|vue)$/,
        loader: 'replace-daddy',
        query: {
          multiple: [
            { search: '__debug__', replace: myConfig.debug || true,  }, //warning: use bool string in condition syntax 
            { search: '__localIP__', replace: getIPAddress(),  },
            { search: '__localPORT__', replace: getHostPORT(), },
            { search: '__imagesDir__', replace: 'images/bar/foo', },
            { search: '__spaDirBuild__', replace:'assets/scripts'},
            { search: '__routerMode__', replace: 'router-split', regexMode:'ig' },
          ]
        }
      }
    ]
  }
}

Dynamic by local config file


# project
import routes from './router/__routerMode__'
import boot from './config/__bootPath__'

# webpack
module.exports = {
  // ...
  module: {
    loaders: [
      {
         test: /\.(js|jsx|vue)$/,
        loader: 'replace-daddy',
        query: {
          multiple: [
             { file: path.join(__dirname, '..', 'api/config.js'), alias: '__daddy__' },
          ]
        }
      }
    ]
  }
}

### CONSTS.js  like 

module.exports = {
    debug: 'dev',//there can be bool, number whatever
    prefix:'ax',
    router: {
        split: true, 
        mode: 'hash', 
    },
    __daddy__: [
        { search: '__prefix__', replace:'prefix', regexMode: 'ig' },
        { search: '__debug__', replace:'debug', regexMode: 'ig' },
        { search: "__routerMode__", replace: { "router.split==true": "router-split", "router.split==false": "router-common" }, regexMode: "ig" },
        { search: "__bootPath__", replace: { "debug=='dev'": "config.dev.js", "debug=='pro'": "config.pro.js" } },
    ]
}

Advanced

tips

  • lot of spa(vue,react,ng) projects(pro1,pro2,pro3) in a single webpack environment, you may need root and key to make your files unique to been replaced

# project
import routes from './router/__routerMode__'
import boot from './router/__bootPath__'

# webpack
module.exports = {
    //...
    module: {
      loaders: [{
        test: /\.(js|jsx|vue)$/,
        loader: 'replace-daddy',
        query: {
            multiple: [
                { search: '__routerMode__', replace: 'whatever', regexMode: 'ig' },
                { root: 'vue', name: 'spafoldername', file: 'api/CONSTS.js', alias: '__daddy__'},
            ]
          }
      }
    ]}
}

Why this loader been created

fake & error code

if (config.router.split) {
    import routes from './router/router-split' //code spliting by router
} else {
    import routes from './router/router-common'
}
// you know why