Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint no-undef and webpack plugin

Tags:

webpack

eslint

I use webpack plugin:

new webpack.DefinePlugin({              
            PUBLIC_KEY:'\'XXX\'',
            CLIENT_ID: '\'XXXX\''
        })



tgc.init({
            publicKey: PUBLIC_KEY,
            clientId: CLIENT_ID     
        });

I use eslint and use Disallow Undeclared Variables (no-undef) rule, so when I write

tgc.init({
            publicKey: PUBLIC_KEY,
            clientId: CLIENT_ID     
    });

I get errors:

'PUBLIC_KEY' is not defined
'CLIENT_ID' is not edfined

How to avoid it? I don't want to disable this rule (with disabled rule all works fine)

like image 928
user348173 Avatar asked Aug 20 '16 11:08

user348173


1 Answers

Add:

  "globals": {
    "PUBLIC_KEY": true,
    "CLIENT_ID": true,
  }

to your eslint.rc -file.

or you can do the same in your webpack config -file as an inline comment like:

/* global PUBLIC_KEY, CLIENT_ID */
like image 146
Hardy Avatar answered Sep 21 '22 18:09

Hardy