[英]'drupalSettings' is not defined no-undef
I have a singe page app that I want to run in every drupal node of a specific content type. 我有一个单页应用程序,我想在特定内容类型的每个drupal节点中运行。
The app is made in react using yarn. 该应用程序是使用纱线在反应中完成的。
In my index.js file I am trying to do the following: 在我的index.js文件中,我尝试执行以下操作:
if(window.location.href !== 'http://localhost:3002/') {
console.log(drupalSettings);
}
However npm run build
or yarn build
are both giving me 'drupalSettings' is not defined no-undef
. 但是
npm run build
或yarn build
都给了我'drupalSettings' is not defined no-undef
。
How can I force npm/yarn to ignore this warning? 如何强制npm / yarn忽略此警告?
When you're using yarn or similar you need to let eslint know that the variable is coming from the global scope. 当您使用yarn或类似的东西时,您需要让eslint知道该变量来自全局范围。 From the eslint docs :
从eslint文档 :
/*global someFunction b:true*/
/*eslint no-undef: "error"*/
var a = someFunction();
b = 10;
Where the b:true
indicates that b
can be changed within the scope of this file. 其中
b:true
表示可以在此文件的范围内更改b
。 For something like drupalSettings
the :true
could be optional since you are most likely pulling info from the page and not setting anything. 对于诸如
drupalSettings
之类的:true
可能是可选的,因为您最有可能从页面中获取信息而不进行任何设置。
For your specific use you would use 对于您的特定用途,您将使用
/*global drupalSettings:true*/
/*eslint no-undef: "error"*/
console.log(drupalSettings)
and you would see the output in your browser's console. 然后您将在浏览器的控制台中看到输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.