How to import external javascript (which requires

2019-08-22 06:45发布

First of all I'm still a newbie in web development. Okay, now to the question. I have these imports:

import $ from 'jquery'; 
window.jQuery = $;
window.$ = $;
global.jQuery = $;
import './assets/js/waves';

How do I properly import an external javascript to reactjs if my external javascript requires jquery?

Because based on what these guys have said:

reactjs, bootstrap and npm import - jQuery is not defined

Are ES6 module imports hoisted?

my imports will be hoisted, which results in my external "./assets/js/waves" js causing an error.

Uncaught ReferenceError: $ is not defined?

Thanks in advance!

1条回答
再贱就再见
2楼-- · 2019-08-22 07:25
import * as jQuery from 'jquery';

Then you have a reference of jQuery and you may do with it what you like, for instance:

window.$ = jQuery;
查看更多
登录 后发表回答