简体   繁体   English

如何使用ES6语法导入jQuery UI并使用browserify?

[英]How can import jQuery UI using ES6 syntax and browserify?

I am trying to import JQuery and JQuery into a project using ES6 syntax using Babel and Browserify to package the code. 我试图使用Babel和Browserify将ES6语法导入JQuery和JQuery到项目中,以打包代码。 From what I have been able to figure out the problem is that JQuery UI expects jQuery to be defined as a global variable. 从我能够弄清楚的问题来看,JQuery UI期望jQuery被定义为全局变量。 I tried setting the global variable after importing jQuery and before importing JQuery UI like this: 我尝试在导入jQuery之后并在导入JQuery UI之前设置全局变量,如下所示:

import { default as $, default as jQuery} from 'jquery';

wiindow.jQuery = jQuery;
window.$ = $;

import 'jquery-ui';

but it seems browserify puts all imports at the top of the file, so the globals are defined too late. 但是似乎browserify将所有导入都放在文件的顶部,因此定义全局变量为时已晚。 I understand that webpack provides a way to define globals but is there a workaround for browserify? 我知道webpack提供了一种定义全局变量的方法,但是浏览器是否有解决方法?

Try this 尝试这个

window.$ = window.jQuery = import $ from "jquery";

or 要么

import { default as $, default as jQuery} from 'jquery';
window.jQuery = windows.$ = jQuery;    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM