我在将velocity.js 集成到我现有的webpack 框架中并让它作为对jquery 的依赖项时遇到了极大的困难。
本质上,velocity.js 期望 jquery(或 $)在全局对象上可用,以便它可以增强功能,从而可以实现以下功能$(elem).velocity
。我曾尝试使用“expose-loader”将两者都暴露jquery
在$
窗口中,但遇到了错误global is not defined
。以下是我的 webpack 配置的摘录
loaders: [
{ test: /\.coffee$/, loader: "coffee-loader" },
{ test: /\.less$/, loader: "style-loader!css-loader!less-loader" },
{ test: /\jquery\.min\.js/, loader: "expose?jQuery!expose?$" },
{ test: /\velocity\.min\.js/, loader: "expose?Velocity" }
]
我也尝试过使用非缩小版。这是加载jquery的错误所在:
module.exports = global["jQuery"] = require("-!/.../node_modules/expose-loader/index.js?$!/.../app/bower_components/jquery/dist/jquery.js");
/*****************
** WEBPACK FOOTER
** ./app/bower_components/jquery/dist/jquery.js
** module id = 6
** module chunks = 0
**/
我不知道暴露加载器是如何工作的,也无法理解上述的意义,特别是因为我能够将velocity.js'暴露Velocity
给全局窗口。
作为后备,我不得不var Velocity = require("velocity")
进入我的应用程序文件并使用velocity.js,就像没有可用的jquery一样,即
Velocity(document.getElementById("rect"), { opacity: 0 }, { duration: 1000 })
任何帮助或建议将不胜感激。