How to know when to import a package or insert it into index.html

Okay, I'm using ES6 and ReactJS, some packages you have to do import React from "react";

to make them work, but others are <script src="/semantic/dist/semantic.min.js"></script>

in index.html

, so what cases should I use one or the other?

+3


source to share


1 answer


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

  • Compile with CommonJS (e.g. using jQuery like CommonJS via npm)
  • Download SystemJS so ES6 can work with CommonJS, AMD and globals

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



import $ from 'jquery';

      

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

+1


source







All Articles