在 ES6 中为 IE8 使用 jquery 的速度
Using velocity with jquery for IE8 in ES6
我正在尝试在 ES6 模块中将速度与 jQuery(仅用于 IE8 支持)一起使用。考虑这段代码:
import { Component } from 'react';
import ReactDOM from 'react-dom';
import jquery from 'jquery';
import velocity from 'velocity-animate';
export default class ScrollTo extends Component {
render() {...}
scrollToTop() {
velocity(ReactDOM.findDOMNode(this), 'scroll', { container: ReactDOM.findDOMNode(this.props.container) });
}
在 IE8 中速度抱怨找不到 jQuery。我检查了源代码,看起来 velocity 在 window 对象上寻找 jQuery,但我将其作为模块导入。
有没有办法 instantiate/bind 使用导入的 jquery 速度?
你可以使用 ShimPlugin 来填充 jquery 和 webpack
见:
https://github.com/webpack/webpack/issues/192
或使用 ProvidePlugin 将 jquery 暴露给 window,这样您就不必在每次需要时都import jquery
。
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
})
plugin ProvidePlugin This plugin makes a module available as variable
in every module. The module is required only if you use the variable.
Example: Make $ and jQuery available in every module without writing
require("jquery").
我正在尝试在 ES6 模块中将速度与 jQuery(仅用于 IE8 支持)一起使用。考虑这段代码:
import { Component } from 'react';
import ReactDOM from 'react-dom';
import jquery from 'jquery';
import velocity from 'velocity-animate';
export default class ScrollTo extends Component {
render() {...}
scrollToTop() {
velocity(ReactDOM.findDOMNode(this), 'scroll', { container: ReactDOM.findDOMNode(this.props.container) });
}
在 IE8 中速度抱怨找不到 jQuery。我检查了源代码,看起来 velocity 在 window 对象上寻找 jQuery,但我将其作为模块导入。
有没有办法 instantiate/bind 使用导入的 jquery 速度?
你可以使用 ShimPlugin 来填充 jquery 和 webpack
见: https://github.com/webpack/webpack/issues/192
或使用 ProvidePlugin 将 jquery 暴露给 window,这样您就不必在每次需要时都import jquery
。
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
})
plugin ProvidePlugin This plugin makes a module available as variable in every module. The module is required only if you use the variable.
Example: Make $ and jQuery available in every module without writing require("jquery").