Skip to content

aminoeditor/webpack-dotenv-to-exports-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dotenv to Exports Plugin

The webpack plugin you never knew you always needed

This plugin will convert your .env files to a file of individual js exports. This is really useful if you're using .env and also have other files with no access to process.env that need the environment variables as well.

Usage Example

const DotenvToExportsPlugin = require('@aminoeditor/webpack-dotenv-to-exports');
{
	...,
	plugins: [
		new DotenvToExportsPlugin({
			// the environment name
			env: process.env.NODE_ENV,
			// output filename in your /dist
			filename: './.env.js',
			// filter entries
			// return false to exclude entry
			filter (key, val) {
				return key.length && val.length;
			},
			// transform entry key
			// alters key name in the resulting file
			transformKey ({key, val}) {
				return `DOTENV_${key}`;
			},
			// transform entry value
			// alters value in resulting file
			transformValue ({key, val}) {
				if (key === 'MUST_BE_UPPER') {
					return val.toUpperCase();
				}
				return val;
			}
		})
	]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published