5

How to Write a Simple NPM Package

 2 years ago
source link: https://hackernoon.com/how-to-write-a-simple-npm-package-pu8359z
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to Write a Simple NPM Package

With ES2015 standard (or ES6), we got built-in modules in JavaScript. Previously it was supported by third-party tooling like RequireJS, for example. In Node, we still use CommonJS in many cases. ES2015 brought a standardization for JavaScript modules. A couple of years later, we have got full support for them on the browser's side and in Node. That's great. But what does it mean?

0 reactions

Imagine that you only need a Typescript compiler to prepare your NPM package written in ES2020 standard. Of course, if you want to write in Typescript. Otherwise, it is also optional. But I think using it is quite reasonable. Anyway, yes, it is possible to use just the language itself without additional processes. What's even better you can now use modern CDN services like Skypack and then import your tool in the browser:

0 reactions
<html>
  <body>
    <script type="module">
      import smoothScrollTop from 'https://cdn.skypack.dev/smooth-scroll-top';
    // do something with it here
    </script>
  </body>
</html>

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK