Skip to content

How to access Environment Variables inside plugin? #15000

Answered by remjx
remjx asked this question in Questions and Help
Discussion options

You must be logged in to vote

My workaround is to pass the environment variable into the plugin function from the config object that is available from the plugin index export function.

In plugins/index.ts:

module.exports = (on, config) => {
  on('task', {
    myPluginFunc: myPluginFunc(config.env.SOME_VAR),
  });
}

In plugins/myPlugin.ts I use the passed env var and return the plugin function:

export const myPluginFunc = (someEnvVar) =>  async ()  => {
    return doSomething(someEnvVar);
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by remjx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant