Ced Ced - 3 months ago 69
Node.js Question

angular 2 directive as npm package

I've a directive that I want to publish on npm. I read the doc here and after that here is what I did:

  • Copy the .js file that is compiled from the .ts file. ( I didn't copy the map file)

  • Make new folder on desktop and paste it there

  • npm init
    npm publish

  • create new project and
    npm install --save-dev
    my published package

However it doesn't find the name of the directive when I'm trying to declare it in the module

declarations: [
MyDirective //this is not found

The js file appears in the module folder though


You imported import {...} from 'your-package-name/your-main-js'; it, right?

Here's a nice guide to create npm packages for Angular2.


If you want to create a component package, remember to inline your templates/styles ! Otherwise your app will be broken..

Or you could use a script like this https://github.com/ludohenin/gulp-inline-ng2-template to inline those templates/styles..

Maybe this repo as a starting point will help: https://github.com/mxii/ng2-offclick