javascript - Do I need to bundle files when publishing a library to npm? - Stack Overflow

My project structure very very roughly looks like this:dist- helperpiled.js- entrypointpiled.jssrc-

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.

Share Improve this question asked May 17, 2020 at 23:07 FoobarFoobar 8,54521 gold badges101 silver badges183 bronze badges 1
  • When publishing a library include the files or the folder in the files section of the package.json – Get Off My Lawn Commented May 17, 2020 at 23:32
Add a ment  | 

2 Answers 2

Reset to default 4

The 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745637626a4637490.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信