【发布时间】:2018-11-16 00:03:10
【问题描述】:
我的 react 组件的结构是这样的。
/build
..............................
/lib
/inner
/InnerComponent.js
/index.js
/OuterComponent1.js
/OuterComponent2.js
/index.js
.................................
package.json
.................................
我的package.json 如下所示
{
"name": "my-comp",
.......................
"main": "build/index.js",
"scripts": {
"build": "babel lib -d build",
"build:watch": "babel lib -w -d build",
"lint": "eslint lib/**; exit 0",
"lint:watch": "esw -w lib/**",
"prepublish": "npm run build"
},
"devDependencies": {
.......................
},
"dependencies": {
.......................
},
"directories": {
"lib": "lib"
},
"repository": {
.......................
}
}
OuterComponent1 和 OuterComponent2 可以从 lib/index.js 导入为 import {OuterComponent1,OuterComponent2} from "my-comp"。我需要将lib/inner 中的所有内容导入为import {InnerComponent} from "my-comp/inner"(我想为lib/inner 文件夹中的组件添加命名空间)。在 npm 中发布后如何执行此操作?
【问题讨论】:
标签: javascript node.js reactjs npm ecmascript-6