Search for the keywords to learn more about each error.
ProvidePlugin传送门
场景: 在react中配置jquery
全局变量,webpack
官网是这么说的,直接写上插件配置,就可以直接使用。照着官网对webpack.config.js
进行文件配置:
webpack.config.js
plugins: [
...
new webpack.ProvidePlugin({
$: 'jquery',
}),
...
]
home.js
import React, { Component } from "react";
import './home.scss'
class Home extends Component {
componentDidMount(){
$('.sh').scrollTop(200)
}
}
export default Home
运行报错了 =_= 百思不得解???。。官网就是这么说的。。。。
去搜了 react ProvidePlugin 。。
结果是eslint
检测报错。由于一些无状态组件没有显式的调用react
。在需要使用的文件夹上面禁掉eslint
:
/* eslint-disable */ //整个下面块不检查
// eslint-disable-next-line 下一行不检查
import React, {Component} from 'react'; // eslint-disable-line 本行不检查
好了,现在在文件上加上/* eslint-disable */
,
/* eslint-disable */
import React, { Component } from "react";
import './home.scss'
...
嗯。。完美~