I'm starting to use JSPM in my Aurelia web projects and I want to know if there are any consequences or advantages in using the import "<client side library>"
?
I've seen code like so for client side libraries inside JS classes :
import "jquery";
import "bootstrap/css/bootstrap.css!"
import "bootstrap";
export class App {
constructor {
}
}
Question: What is the difference/advantages/disadvantages between importing it this way as oppose to the traditional include of <script>
and <link>
tags in the .html
file?
<html>
<head>
<link rel="stylesheet" src="<bootstrap path>/bootstrap.css">
</head>
<body>
<script type="text/javascript" src="<bootstrap path>/bootstrap.js"></script>
</body>
</html>
My trial and error shows me that by using import
in a particular class/js file, it limits the libraries to that particular view file as oppose to being globally available.
Ultimately when you go to build these project for production, don't these libraries need to exists in the index.html?
My opinion is: you should use the
import
keyword, and here is why:import
, so it might confuse themimport
takes care of loading that, so if you just add a script tag, you might add someimport
and then some function might be redeclared.<script>
tags in your codeRollup is another pro for using
import
. What it does is ripping the libraries you use and taking the minimal amount of code you need, so if you need only some stuff from, let's say, jQuery, you won't need to make your visitors download 50KB (or how much is it now?).You can read more about Rollup here.