我的包的结构如下:
mypackage
|--- src
| |--- component1
| `--- component2
`--- dist
|--- component1
`--- component2
当我将它发布到npm时,我希望它看起来如下,没有dist
目录:
mypackage
|--- component1
`--- component2
我的想法是,当我从这个包导入时,导入应该看起来是这样的文件:
import component1 from 'mypackage/component1'
不是这个(注意额外的dist
):
import component1 from 'mypackage/dist/component1'
如何实现这一目标?我目前在package.json中有一个文件部分,该部分使用额外的dist
发布,我不希望这样:
"files": [
"dist/"
]
答案 0 :(得分:3)
基于How to publish contents only of a specific folder?的答案,这可能有用:
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
所以基本上将你的package.json复制到dist/
文件夹中,然后从npm publish
文件夹中运行dist/