简体   繁体   English

npm模块和angular-cli @ webpack

[英]npm modules and angular-cli@webpack

How should one package angular2 components in a mpm module so it can be imported and used in an application compiled with angular-cli@webpack. 如何将angular2组件打包到一个mpm模块中,以便可以导入并在使用angular-cli @ webpack编译的应用程序中使用它。

What should be published in the npm package ? 什么应该在npm软件包中发布? The source (*.ts, *.css, *.html) or the webpack compiled version ? 源(* .ts,*。css,*。html)还是webpack的编译版本?

see my related question : angular-cli@webpack : Components imported in npm dependencies don't work 看到我相关的问题: angular-cli @ webpack:在npm依赖项中导入的组件不起作用

First, install Yeoman and generator-angular2-library using npm (assuming you already have node.js pre-installed). 首先,使用npm安装Yeoman和generator-angular2-library(假设您已经预安装了node.js)。

$ npm install -g yo
$ npm install -g generator-angular2-library

make a new directory and cd into it: 制作一个新目录并cd进入:

$ mkdir angular2-library-name
$ cd angular2-library-name

and generate your new library: 并生成您的新库:

$ yo angular2-library

and create the following files for you: 并为您创建以下文件:

.
├── 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

You can then add or edit *.ts files in the src/ directory and run: 然后,您可以在src /目录中添加或编辑* .ts文件并运行:

$ npm run tsc
$ npm run lint

Once you have published your library to the NPM registry, you can import it in any Angular application by first installing it using NPM: 将库发布到NPM注册表后,可以先通过使用NPM安装它,将其导入任何Angular应用程序中:

$ npm install sample-library # use the name you used to publish to npm

Detailed description available here . 详细说明可在此处获得

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM