【问题标题】:ES6 import – jQuery is not definedES6 导入 - 未定义 jQuery
【发布时间】:2016-06-24 00:15:12
【问题描述】:

我在构建过程中使用 Gulp 和 Browserify,但在使用第三方 jQuery 插件时遇到问题 - 显示错误 jQuery is not defined

以下是我的文件结构。

app.js

import $ from 'jquery'
import plugin from 'jquery-plugin'

jquery-plugin.js

(function($) {

    // Plugin code here

}(jQuery));

有什么想法吗?

【问题讨论】:

  • 您将need to shim 这些模块。大多数 jQuery 插件不支持 UMD/CJS/AMD 所以 Browserify 不知道如何定位依赖项

标签: javascript jquery ecmascript-6 browserify


【解决方案1】:

也许你需要使用'./'

import $ from 'jquery' import plugin from './jquery-plugin'

已编辑,我的新答案如下:

试试这个方法:

import * as jqueryPlugin from 'jquery-plugin'

【讨论】:

  • 他是从 node_modules 导入的,所以 './' 不是必需的。从相对目录导入文件时,我们使用 './'。
  • 你是对的......也许他可以这样使用import * as 例如:import * as _ from "lodash"
猜你喜欢
  • 2016-05-23
  • 2018-03-18
  • 2017-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-21
相关资源
最近更新 更多