0.6.2 • Published 2 years ago

@best-shot/preset-env v0.6.2

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

@best-shot/preset-env

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"'
    })
  ]
};
0.6.2

2 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.6

4 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago