I have a javascript library that I want to publish on npm: let's call it foo
.
The problem is that the javascript files to be consumed by the clients are under a dist
folder.
Therefore, for the moment the clients has to include dist
in their import
statement like this:
import { bar } from 'dist/foo'
I would like to allow clients to import the foo
library without mentioning dist
explicitly, like this:
import { bar } from 'foo'
Is there a way to add a property in package.json
of foo
or maybe in the package.json
of the clients?
Remark: The reason why the javascript files are in a dist
folder is because my library is written in clojurescript
. Therefore the source files are under src
and the generated files are under dist
.
It will create the node_modules directory in your current directory (if one doesn't exist yet), and will download the package to that directory. npm install has nothing to do with creating (or failing to create) the dist folder, which is what OP is asking about.
dist/ is the distribution version that has been modified to perform better for users not looking to modify how the code works.
The dist directory is not any special, but it's very common to have a dist directory that contains an UMD build. Especially as Unpkg allows you to import a node module without having to publish it manually to a CDN, it uses the dist or umd by default (as described at the bottom of the homepage).
You can add a main
section in your package.json
:
main: If you have a single module that serves as the entry point to your program (like what the "foo" package gives you at require("foo")), then you need to specify that in the "main" field.
ref: https://docs.npmjs.com/misc/developers
But it will only work for a single file, if you need to require
multiple files, you should only publish your dist
folder :
npm publish dist
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With