I want to publish npm package and have next type of import:
import { Component } from "my-lybrary/Component"
I found out that I have to copy my package.json to dist directory and run npm publish ./dist. Well, it works, but final package doesn't have directory node_modules, that I have in dist after building. How can I save node_modules directory?
- I tried to add !node_modules/ at .npmignore
- I tried to publish from root directory (my package.json has
files: ["dist"], but in this case I have incorrect structure:
- my-lybrary --dist ----component
instead of
- my-lybrary --component
Publishing
node_moduleswithin your package isn't typical or recommended due to potential bloat and dependency conflicts. Instead, list your dependencies inpackage.json. Consumers installing your package will have these dependencies resolved automatically. If you need specific modules within your package, consider bundling them into your distribution files using tools like Webpack or Rollup. This way, you maintain a clean package structure and prevent issues related to directly includingnode_modules.