Easiest Way to Write a NPM Module in ES2015

Arunoda Susiripala
KADIRA VOICE
Published in
2 min readDec 11, 2015

Spoiler Alert: If you are a Meteor developer, you may need this soon.

We all wanna write our apps in ES2015. That’s the best thing happen to JavaScript ever.

Setting up the development environment for ES2015 is kind of a pain(sometimes). Fortunately, there are tons of boilerplates you can choose as the base for your project. Specially there are a lot of boilerplates for React with Webpack.

If you are using Meteor, ES2015 support is enabled by default. With that, I think it’s the easiest way to get started with ES2015.

Okay, what about NPM modules?

If you are trying to write a NPM module in ES2015, it could be a bit harder to find a simple and clean boilerplate.

I couldn’t find a good one. So, I decided to write a one from scratch with Babel-6. That’s npm-base. It’s pretty easy to use.

  • Just clone this repo: https://github.com/kadirahq/npm-base
  • Then install dependencies with npm install.
  • Change the package.json as you want.
  • Start writing code inside lib/index.js
  • Then publish to NPM via npm publish

npm-base will take care of all the hard work for you and it comes with optimal configurations.

You can also lint and test your code right away.

Give it a try, you’ll like it.

I am a Meteor Developer, Do I need this?

Yes, You will.

Really!

Meteor will support ES2015 modules sooner. As a bonus of that, you’ll be able to use any NPM packages directly with Meteor.

Okay. I’m listening.

With that, you may wanna publish your re-usable Meteor packages directly to NPM rather than pushing them to Atmosphere. Matt, one of the co-founders of Meteor Development Group also mentioned it in the Meteor Forums.

I saw that. But, he didn’t exactly say you should publish to NPM..

Yeah, I get. But, it kind a sound like that.

Anyway, it’s fair to assume you’ll need to write a lot of NPM modules in the future. So, npm-base will help you.

Hmm.

--

--