I'm trying to make a small-ish react component that can be used in other projects. This is what I have in my package.json so far:
{
"name": "my-package",
"version": "0.1.1",
"private": true,
"main": "./dist/lib.umd.js",
"module": "./dist/lib.module.js",
"source": "src/components/MyPackage/index.js",
"exports": {
".": "./dist/lib.js",
"./styles.css": "./dist/lib.css"
},
"dependencies": {
"classnames": "^2.3.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"microbundle": "^0.15.0",
"react-scripts": "5.0.1"
},
"peerDependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"scripts": {
"start": "react-scripts start",
"build": "microbundle --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react",
"watch": "microbundle watch --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react"
},
"eslintConfig": {
"extends": [
"react-app"
]
},
"files": [
"dist"
],
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
The exports
fields, module
and source
are for microbundle to know what and where to bundle.
This repo is in a private bitbucket repository, and I've installed it like this: npm i git+ssh://git@bitbucket.org:myuser/mypackage.git
, but it doesn't let me import the package. When looking in my node_modules/mypackage
, I only see the package.json, and the README, but no js files.
The weird thing is this package works when I import it locally using npm link
.
"publishConfig": {
"registry": "https://registry.npmjs.org"
}
More details can be foundhere
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.