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 🙏

© 2025 – Pkg Stats / Ryan Hefner

config-plugin

v0.0.2

Published

管理配置文件的Webpack插件,支持环境名、local.

Downloads

18

Readme

config-plugin

管理配置文件的Webpack插件,支持环境名、local.

如何使用

首先,通过npm安装

$ npm i --save-dev config-plugin

然后,在webpack的配置文件内加上以下代码段

const ConfigPlugin = require('config-plugin')

module.exports = {
  ...
  plugins: [
    new ConfigPlugin({
      dir: '/full/path/to/config/dir'
    })
  ]
}

这时,dir参数指定的目录下的config.jsconfig.local.js文件会被读取,并赋值为名为CONFIG的全局变量。其中优先级为config.local.js > config.js. 如:

// config.js
module.exports = {
  a: 1,
  b: 2
}

// config.local.js
module.exports = {
  b: 3,
  d: 4
}

// index.js
console.log(CONFIG) // { a: 1, b: 3, d: 4 }

进阶用法

指定env参数

在构建ConfigPlugin的时候,如果传递了env参数,则会多读一个文件config.[env].js,如:

new ConfigPlugin({
  dir: '/full/path/to/config/dir',
  env: 'dev'
})

则读取的文件依次为config.jsconfig.dev.jsconfig.local.js,后者的优先级大于前者。env参数不仅可以是devprod等,它可以是任意的字符串。

指定name参数

指定name参数可以定义Config对象的变量名,如

new ConfigPlugin({
  dir: '/full/path/to/config/dir',
  env: 'dev',
  name: 'Settings'
})

// index.js
console.log(Settings) // { a: 1, b: 3, d: 4 }

推荐实践

通过环境变量管理dev参数

webpack.config.js内,我们用环境变量管理dev参数,如:

const env = process.env.ENV

module.exports = {
  ...
  plugins: [
    new ConfigPlugin({
      dir: path.resolve(__dirname, 'config'),
      env: env
    })
  ]
}

然后通过传递环境变量读取不同的配置文件列表,如:

ENV=dev webpack webpack.config.js

会依次读取config.jsconfig.dev.jsconfig.local.js.

将config.local.js放在.gitignore内

我们将默认配置放在config.js内,与环境相关的变量放在config.[env].js内,config.local.js给了依次机会覆盖上面的两个配置文件。

config.local.js适合放一些敏感信息,如密钥等;或者在本地调试的时候覆盖之前的配置。这说明config.local.js应该被git ignore掉,不适合放在版本库内管理。

License

MIT