1

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

1
  • So make an npm package for them to import and use the functions. What is the exact issue? Commented Feb 5, 2021 at 19:26

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Following approach might be suitable for your client's requirement.

  1. Create a NPM project using the javascript file you have
  2. Publish it on client's Github account as a package.
  3. Create a .npmrc file in root of your client's project.
  4. 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).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.