A client would like to use an npm package to access our JavaScript file's functions instead of adding a script tag to their html. Is this possible? The only resource I've come across for creating an npm package is for NodeJS files (https://docs.npmjs.com/creating-node-js-modules).
2 Answers
This is possible but you cannot import the npm package and have it work in the browser without some sort of bundling system like webpack.
Alternatively, which is a bad idea, would be to ship your dist folder with node_modules in it. This isn't recommended for a multitude of reasons, but it will work.
Comments
Following approach might be suitable for your client's requirement.
- Create a NPM project using the javascript file you have
- Publish it on client's Github account as a package.
- Create a .npmrc file in root of your client's project.
- Add your package in .npmrc file and in packages.json both.
Refer this doc for using a package with .npmrc file: https://docs.github.com/en/packages/guides/configuring-npm-for-use-with-github-packages#installing-a-package).