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

@zhupengji/create-config

v1.0.3

Published

frontend pages'configuration files generator

Downloads

20

Readme

create-config

CC(create-config) is a tool to generate a front-app-configuration-file for web pages' deployment.

create-config

Get Started

npm i --save-dev create-config

add a quick script in package.json:

{
  "scripts": {
    "config": "create-config"
  }
}

If you have a .env file, and there are variables starts with config_

config_XXXX=XXXX

After run npm run config, then you can find dist/_app.config.js contains the content:

window.APP_CONFIG = {
  config_XXXX: "XXXX",
};
Object.freeze(window.APP_CONFIG);
Object.defineProperty(window, "APP_CONFIG", {
  configurable: false,
  writable: false,
});

Or your can custom your own prefix by additional -x, for example:

{
  "scripts": {
    "config": "create-config -x VITE_"
  }
}

Usage

  1. Modify your html entry file manually or by tools like webpack.
<script src="./_app.config.js"></script>
  1. Using global config data in condition.
function getGlobalConfig() {
  if (process.env.NODE_ENV === "production") return window["APP_CONFIG"];
  // ... otherwise
}

Further

Javascript API

You will rarely to use this. It's recommended to use in the npm-scripts way.

Use in your node code, usually at post-build stage. Provide the config object.

const { createConfig } = require("create-config");

createConfig({
  config: {
    config_api_url: "http://localhost:8080",
  },
});

options

| key | default | description | | -------------- | ------------------ | ---------------------------------------------- | | config | - | required | | output | "dist" | - | | configName | "APP_CONFIG" | - | | configFileName | "_app.config.js" | - | | prefix | "config_" | case sensitive; if you use vite, maybe VITE_ | | packageName | - | npm_package_name + npm_package_version |

CLI

We provided a CLI for convenience when using npm-scripts.

Here is the options(you can get the list by npx create-config --help):

  -o, --output <string>            output directory where to put the generated file (default: "dist")
  -f, --config-file-name <string>  filename of the generated file (default: "_app.config.js")
  -n, --config-name <string>       the key name of global(window) (default: "APP_CONFIG")
  -x, --prefix <string>            only keys start with the prefix would be preserved (default: "config_")
  -h, --help                       display help for command

Without dotenv

It's recommended to use dotenv, which is used widely in modern front-end dev environments. We automatically read configs from your .env.production | .env file.

Besides, there is one more way without dotenv. A appConfig.json at root is also available.

| - appConfig.json
| - .env.production
| - .env