ESLint no-undef and webpack plugin

2020-03-24 08:56发布

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)

1条回答
啃猪蹄的小仙女
2楼-- · 2020-03-24 09:16

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 */
查看更多
登录 后发表回答