My project structure very very roughly looks like this:
dist/
- helperpiled.js
- entrypointpiled.js
src/
- helper.js
- entrypoint.js
I was reading the npm publishing guidelines and it says to provide a single index.js file. But is this really necessary? Afterall, my entrypointpiled.js
can just require helperpiled.js
. What is the benefit of providing a single index.js
file?
What is the remended procedure for publishing a library to npm in this situation? I tried using npm pack
, but I don't quite understand what it is doing.
My project structure very very roughly looks like this:
dist/
- helper.piled.js
- entrypoint.piled.js
src/
- helper.js
- entrypoint.js
I was reading the npm publishing guidelines and it says to provide a single index.js file. But is this really necessary? Afterall, my entrypoint.piled.js
can just require helper.piled.js
. What is the benefit of providing a single index.js
file?
What is the remended procedure for publishing a library to npm in this situation? I tried using npm pack
, but I don't quite understand what it is doing.
-
When publishing a library include the files or the folder in the
files
section of thepackage.json
– Get Off My Lawn Commented May 17, 2020 at 23:32
2 Answers
Reset to default 4The best way to bundle just the piled files is to put the directory in the files
section of your package.json
. This will then only package the files that npm uses such as package.json
, README.md
, and other files that your package requires.
An example package.json
looks something like this:
{
"name": "my-library",
"version": "1.0.0",
"description": "My Library.",
"main": "dist/entrypoint.piled.js",
"scripts": {},
"author": "",
"license": "ISC",
"dependencies": {},
"files": [
"dist"
]
}
You need only to publish the piled files. If you pile them correctly then there is no need to include your src/
folder in the package.
Here is my .npmignore
file for my tree in react package: .npmignore
You can see what is in the package here.
As you can see, I publish only the dist
directory and every file in the root. The bare minimum is the package.json
and the dist
directory.
npm publish
mand essentially just creates a package from your files and uploads it to the npm registry. After running the mand you will be able to find the npm package and use it as any other package.
After you run npm publish
I remend downloading published the package from the registry and try out if all the required files are there and verify that you can use everything.