@best-shot/preset-env

0.6.2 • Public • Published

@best-shot/preset-env logo

A best-shot preset for env variables.

npm github node

The package will find the configuration from process.cwd() according to the following priority:

  • ./best-shot/env.toml
  • ./best-shot/env.ini
  • ./best-shot/env.yaml
  • ./best-shot/env.json

Then parse your env variable with JSON.stringify and pass it to webpack.DefinePlugin.

Installation

npm install @best-shot/preset-env --save-dev

Usage

// example: .best-shot/config.mjs
export default {
  presets: ['env'],
  define: {
    WHATEVER: 'abc'
  }
};
# example: .best-shot/env.ini

[production]
SERVICE_URL = "https://sample.org/"
APPID = "123456789"

[development]
SERVICE_URL = "http://sample.dev/"
APPID = "987654321"

[serve]
SERVICE_URL = "http://mock.dev/"
// output: production mode
export const production = {
  plugins: [
    new DefinePlugin({
      APPID: '"123456789"',
      SERVICE_URL: '"https://sample.org/"',
      WHATEVER: '"abc"'
    })
  ]
};

// output: development mode
export const development = {
  plugins: [
    new DefinePlugin({
      APPID: '"987654321"',
      SERVICE_URL: '"http://sample.dev/"',
      WHATEVER: '"abc"'
    })
  ]
};

// output: serve command
export const serve = {
  plugins: [
    new DefinePlugin({
      APPID: '"987654321"',
      SERVICE_URL: '"http://mock.dev/"',
      WHATEVER: '"abc"'
    })
  ]
};

Tips

Namespace safety

Don't use built-in module name like:

__dirname = 123456
console = "xyz"

Git hash inject

If a process.cwd() is a git repository, GIT_HASH will be injected to your config too.

export default {
  plugins: [
    new DefinePlugin({
      'BEST_SHOT.GIT_HASH': '"xxxxxxxxxxxxxxxxxxxx"'
    })
  ]
};

Dependencies (7)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @best-shot/preset-env

    Weekly Downloads

    21

    Version

    0.6.2

    License

    MIT

    Unpacked Size

    7.62 kB

    Total Files

    5

    Last publish

    Collaborators

    • airkro