我有一个我想在npm上发布的指令。我读了the doc here,之后就是我做的:
npm init
和npm publish
npm install --save-dev
我发布的包但是当我试图在模块中声明它时,它找不到指令的名称
@NgModule({
declarations: [
AppComponent,
MyDirective //this is not found
],
js文件虽然出现在模块文件夹中
答案 0 :(得分:1)
您导入了import {...} from 'your-package-name/your-main-js';
,对吗?
这是为Angular2创建npm包的一个很好的指南。
https://medium.com/@OCombe/how-to-publish-a-library-for-angular-2-on-npm-5f48cdabf435#.coog6uf98
如果要创建组件包,请记住内联模板/样式!否则你的应用程序将被破坏..
或者您可以使用像https://github.com/ludohenin/gulp-inline-ng2-template这样的脚本来内联这些模板/样式..
也许这个回购作为起点会有所帮助:https://github.com/mxii/ng2-offclick
您还可以查看以下资源:
答案 1 :(得分:0)
以防将来有人在挣扎,就像我在这里做的那样是重要的一步。
package.json
并添加必要的devDependencies .npmignore
中的.ts文件:node_modules npm-debug.log *.ts !*.d.ts
我希望我没有错过任何内容,无论如何,上面接受的答案中的教程将有所帮助