Gem 一覧へ戻る
Andarist/rollup-plugin-dotenv(新しいタブで開きます)
主要言語: JavaScript
- star 数
- 33
- watcher 数
- 1
- fork 数
- 11
- issue 数
- 2
- 最終更新
- 2024/04/15
主要言語: JavaScript
npm install rollup-plugin-dotenvCreate a rollup.config.js configuration file and import the plugin:
import dotenv from "rollup-plugin-dotenv" export default { input: "src/index.js", output: [ dir: "dist/build" ], plugins: [ dotenv() ] }
create your .env file in the root of your project.
# .env
FOO=barso you can use FOO in your javascript files.
// src/index.js console.log(process.env.FOO)
your env variables will be replaced by their values in your bundled file.
// dist/build/index.js console.log('bar')
if you want to know more about the principle and restrictions of replacement, please read @rollup/plugin-replace notes.
You can specify the options below.
Type: String
Default: "."
directory in which to search for env files.
Type: String
Default: "NODE_ENV"
key used to search for .env files by node environment
Rollup will merge env vars located at
[
`.env.${process.env[envKey]}.local`,
`.env.${process.env[envKey]}`,
'.env.local',
'.env',
]
so if you are in prod, rollup will search in
['.env.prod.local', '.env.prod', '.env.local', '.env']
and merge the result.