Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack.DefinePlugin usage #122

Closed
ilan-toluna opened this issue Dec 17, 2018 · 1 comment
Closed

webpack.DefinePlugin usage #122

ilan-toluna opened this issue Dec 17, 2018 · 1 comment

Comments

@ilan-toluna
Copy link

Hi
I would like to inject global js variables into the extension.

So i edit webextension-toolbox-config.js like so:

module.exports = {
webpack: (config, { dev, vendor }) => {
config.plugins.push( new webpack.DefinePlugin({ GLOBAL_VAR: "value" }) );
return config;
}
}

However, GLOBAL_VAR is not defined in background context nor in popup

How can we achieve this using the toolbox?

@HaNdTriX
Copy link
Contributor

Hey @ilan-toluna

First of all you have a little error in your code above. You need to JSON.stringify the value (More Info).

Here is the correct configuration:

const webpack = require('webpack')

module.exports = {
  webpack: (config, { dev, vendor }) => {
    config.plugins.push(new webpack.DefinePlugin({
      GLOBAL_VAR: JSON.stringify('value') 
    }))
    return config
  }
}

In addition to that please keep in mind that webpack replaces any occurrence of the keyword GLOBAL_VAR in your code. It won't define the variable for you. In other words: The keyword GLOBAL_VAR must be present at build time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants