Skip to content

P. Running the finished product locally

Cody Brunner edited this page Mar 13, 2017 · 3 revisions

So you've done it! You've made your very first npm package, but you are nervous about it actually working in someone else's project. Why not test it out locally!

npm pack || yarn pack

Yellow-Stone:picnic-basket-generator yogibear$ npm pack

This command will create: picnic-basket-generator-0.1.0-beta.0.tgz which your text editor will have no ability to read (or at least mine couldn't), but if you run:

Yellow-Stone:picnic-basket-generator yogibear$ open picnic-basket-generator-0.1.0-beta.0.tgz

You will notice that a package directory appears in your project directory. This is your npm package! This is what the package directory looks like based off of what we declared in our PJ & webpack.config.js

package/
  dist/
   picnic-basket-generator.js
   picnic-basket-generator.js.map
   picnic-basket-generator.min.js
   picnic-basket-generator.min.js.map
  lib/
   index.js
   rcjh.js
  LICENSE
  package.json
  README.md

Actually running the package

I made a script for running the package locally right from inside the actual package & created sandbox.js for giving the package a go. You can also open a new project locally and import from there, totally up to you:

"test:package": "babel-node sandbox.js",

sandbox.js

const rcjh = require('./package/lib').rcjh;
// OR
import { rcjh } from './package/lib';

const result = rcjh();

console.log(result); // ROCK CHALK JAYHAWK, KU!