应该如何将angular2组件打包到mpm模块中,以便导入并在使用angular-cli@webpack编译的应用程序中使用。
npm包中应该发布什么?源代码(*.ts,*.css,*.html)还是webpack编译的版本?
请看我的相关问题:angular-cli@webpack : Components imported in npm dependencies don't work
发布于 2017-02-16 20:11:56
首先,使用npm安装Yeoman和generator-angular2-library (假设您已经预先安装了node.js )。
$ npm install -g yo
$ npm install -g generator-angular2-library创建一个新目录并将cd放入其中:
$ mkdir angular2-library-name
$ cd angular2-library-name并生成新的库:
$ yo angular2-library并为您创建以下文件:
.
├── README.MD
├── index.ts
├── package.json
├── src
│ ├── sample.component.ts
│ ├── sample.directive.ts
│ ├── sample.pipe.ts
│ └── sample.service.ts
├── tsconfig.json
├── tslint.json
└── typings.json然后,您可以在src/目录中添加或编辑*.ts文件,并运行:
$ npm run tsc
$ npm run lint将库发布到NPM注册表后,可以将其导入任何Angular应用程序,方法是首先使用NPM进行安装:
$ npm install sample-library # use the name you used to publish to npm详细说明可用here。
https://stackoverflow.com/questions/39407600
复制相似问题