如何知道何时导入包或将其粘贴到index.html中 [英] How to know when to import a package or paste it in index.html

查看:73
本文介绍了如何知道何时导入包或将其粘贴到index.html中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OK,我正在使用ES6和ReactJS,您应该执行的一些软件包 importreact; 为了让它们工作,而其他<$ c $在 index.html 中的c>< script src =/ semantic / dist / semantic.min.js>< / script> 那么,我应该应用什么样的一个或另一个?

OK, I am using ES6 and ReactJS, some packages you should do import React from "react"; in order to have them working, but others <script src="/semantic/dist/semantic.min.js"></script> in index.html, so, what cases should I apply one or another ?

推荐答案

一般来说,有两种类型的模块。 ES6和非ES6。如果要使用非ES6模块与ES6,您可以尝试以下方法之一:

In general, there are two types of modules. ES6 and non-ES6. If you want to use a non-ES6 modules with ES6, you can try one of the following approaches:


  1. 编译CommonJS(for例如使用jQuery作为CommonJS通过npm)

  2. 加载SystemJS以允许ES6使用CommonJS,AMD和全局变量

如果不想这样做,可以尝试以HTML格式导入非ES6脚本。在这种情况下,您不会像

If you don't want to do this, you can try importing the non-ES6 scripts in HTML. In which case, you won't be doing something like

import $ from 'jquery';

所以简而言之,如果你想使用非ES6模块而不用CommonJS进行编译,通过npm不可用,您可以使用HTML导入而不是ES6导入

So in short, if you want to use a non-ES6 module without compiling with CommonJS or if it is not available through npm, you can use HTML imports instead of ES6 import

这篇关于如何知道何时导入包或将其粘贴到index.html中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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