将Velocity.js与Webpack一起使用 [英] Use velocity.js with webpack

查看:130
本文介绍了将Velocity.js与Webpack一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用materialize-cssjs的某些部分,其中一些部分取决于速度,而我依赖于jQuery的其他一些代码块.我正在使用webpack来构建所有内容.

I'm trying to use some parts of materialize-css, js, some of these parts depend on velocity and some other chunks of code that I have depend on jQuery. I'm using webpack to build it all.

要求速度对我不起作用,我仍然得到.velocity is not a function.我使用ProvidePlugin注入jQuery(随npm安装),其中使用了$jQuery,并且效果很好.

requiring velocity is not working for me, I still get a .velocity is not a function. I use ProvidePlugin to inject jQuery (installed with npm) where $ or jQuery are used, and this is working nice.

plugins: [
  new webpack.ProvidePlugin({
    $: "jquery",
    jQuery: "jquery",
  })
]

但是,看来速度无法将velocity方法注入jQuery.我也尝试过:

However looks like velocity is not being able to inject velocity method into jQuery. I've also tried:

module: {
  loaders: [
    {
      test: /jquery\.js$/,
      loader: "expose?jQuery!expose?$"
    }

推荐答案

如果查看Velocity.js的节点模块,它将使用window.jQuery 您应该尝试将window.jQuery代替添加到webpack ProvidePlugin

if you look in velocity.js's node module, it uses window.jQuery you should try adding window.jQuery instead to the webpack ProvidePlugin

plugins: [
    new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "window.jQuery": "jquery"
    })
]

这篇关于将Velocity.js与Webpack一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆