I hope this question won't be too opinionated, I'm asking about the best/common practice for this.
I'm publishing an npm module written in ES6 and transpiled to ES5 and UMD using babel and rollup.
The file structure could be summarized like this:
/coverage/ /dist/ /node_modules/ /src/ /test/ /tools/ .editorconfig .eslintrc .gitattributes .gitignore .travis.yml CHANGELOG.md CONTRIBUTING.md LICENSE.txt package.json README.md
The source code is within /src/
and the compiled code in /dist/
.
These dirs are .gitignored:
What the user would really use is indeed the content of /dist/
.
I've been using a starter kit with a build process that:
package.json
The entire package source will be published on GitHub but I'm not sure about what to publish on npm:
A) the entire file structure (removing /coverage/
and /node_modules/
) with a top level package.json
that has an entry point to the relevant file in dist
or
B) just publish the content of dist
with a stripped down package.json
and the README & LICENSE. I know that just publishing the content of /dist
would render source maps useless.
What is the common practice here?
it's usually unnecessary to minify your code, since they all implement their own build pipeline, often through a cli.
When you run npm publish , npm bundles up all the files in the current directory. It makes a few decisions for you about what to include and what to ignore. To make these decisions, it uses the contents of several files in your project directory. These files include .
json and publish it to npm using the same version. You can't publish again using the same version, or a previous one. You can read more about versioning here. Don't forget to build before publishing.
social is our first Dapp using Dev protocol, and let you monetize your npm packages and share them with your contributors. On Stakes. social, the number of downloads of your NPM package turns into revenue. (This is the very first way in which OSS can be monetized as an asset.)
In my opinion, the best practice is to publish both minified code in dist
folder and also the source code in src
folder. One should also include other files such as package.json
, package-lock.json
, README.md
, LICENSE.txt
, CONTRIBUTING.md
, etc which are at the root package directory.
To achieve this, one should use files
property in package.json
to whitelist what needs to be published to npm
instead of finding what is not required to be published by blacklisting in .npmignore
.
The dist
folder should have only minified bundle and no need to generate another package.json
in dist folder by removing scripts, devDependencies
, etc.
This is because when consumer of package do npm install <package name>
, it installs only the packages inside dependencies
and ignores packages under devDependecies
.
The minified files can be used by browser by referring directly from scripts tag where load time will be smaller due to small file size while modern frameworks such as angular
will use un-minified code. Modern frameworks have their own build tools, like webpack
/rollup
which create a minified bundle-file.
There is no need to have a top level package.json
that has an entry point in the main
field to the relevant file in dist
. Instead, in my opinion, the top level package.json
should have entry point to relevant file such as index.js
at the same root package level.
Finally, one can run npm pack
to see what is inside the tarball and then finally do npm publish
to npm registry for public use from inside root package folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With