Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm publish a package with only the children of dist folder [duplicate]

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/"
]
like image 210
Naresh Avatar asked Jan 06 '18 06:01

Naresh


People also ask

Should I minify my npm package?

it's usually unnecessary to minify your code, since they all implement their own build pipeline, often through a cli.

How npm install specific dependencies?

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.

How do I fix dependencies in npm?

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.


1 Answers

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

like image 83
Jordan Whitfield Avatar answered Sep 26 '22 07:09

Jordan Whitfield