@best-shot/preset-env
v0.6.2
Published
A `best-shot` preset for env variables
Downloads
54
Maintainers
Readme
@best-shot/preset-env
A best-shot
preset for env variables.
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"'
})
]
};