My package is structured as follows:
mypackage
|--- src
| |--- component1
| `--- component2
`--- dist
|--- component1
`--- component2
When I publish it to npm, I would like it to look like the following, without the dist
directory:
mypackage
|--- component1
`--- component2
The idea is that when I import from this package, the imports should look file this:
import component1 from 'mypackage/component1'
an not this (notice the extra dist
):
import component1 from 'mypackage/dist/component1'
How to achieve this? I currently have a files section in my package.json which publishes with the extra dist
and I don't want that:
"files": [
"dist/"
]
it's usually unnecessary to minify your code, since they all implement their own build pipeline, often through a cli.
Summary. For npm install specific version, use npm install [package-name]@[version-number]. Use npm view [package-name] version to know the specific latest version of a package available on the npm registry. Use npm list [package-name] to know the specific latest version of an installed package.
Audit. Npm has an audit functionality that can be used to identify which packages are responsible for the vulnerabilities. The easy fix is to use the npm audit --fix which will look for updates that can be updated to fix those automatically. But those are usually already fixed or not the real problem.
Based on the answer from How to publish contents only of a specific folder? this may be of use:
npm run build
cp package.json ./dist
# or, if you need to have package.json "main" entry different,
# e.g. for being able to use `npm link`, you need to replace "main"
value:
# sed 's#"main": "./dist/index.js"#"main": "./index.js"#' package.json > ./dist/package.json
cd ./dist
npm publish
So just basically copy your package.json into the dist/
folder and then run npm publish
from within the dist/
folder
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