javascriptnpmnpm-publishnpm-package

How to publish js + assets files to npm


I've developed a small Ui component for internal use in a company and published it to npm but when I install that package I only get an index.js file in node_modules folder.

I'm not using any package builder, es-modules, just a straightforward .js and .css

The folder i want to publish as the package has the following structure:

package
 - src
   - index.js
   - index.css
   - assets/
     - fonts/
       - ..some fonts
     - images/
       - icon.svg
 - package.json

Solution

  • Use npm publish --dry-run to see what npm thinks it should be publishing. (Another possibility is to use npm pack and then examine the contents of the resulting tarball.)

    If you have files missing, check the contents of any relevant .npmignore file or a .gitignore file, either of which might cause npm to ignore a file. (Read the relevant npm docs if you are not familiar with how that all works.)

    Lastly, check your package.json to see if there is a files: entry, "which is an array of file or directory names that should be included in your package" (according to the docs previously linked). If you have a files: entry, add the files you want published that aren't being included.