Ernesto
Ernesto

Reputation: 31

How do you add third party packages when doing an Angular 2 CLI Project

I am currently working on an Angular 2 project that uses the Angular 2 CLI structure. I am able to add moment, ng-material2, ng2-bootstrap those are fine, but if I attempt to add a package like JsonWebToken then I am unable to properly setup my files.

Note: jsonwebtoken is not built for Angular 2 or Angular 2 CLI. It is just a npm package that I am attempting to use.

I have tried following the setup described in the angular2-cli 3rd party libs and it still does not work.

Here is how I am setting it up:

Angular-cli-build.js:

/* global require, module */

var Angular2App = require('angular-cli/lib/broccoli/angular2-app');

module.exports = function (defaults) {
  return new Angular2App(defaults, {
    vendorNpmFiles: [
    /* more code here */
    'jsonwebtoken/**/*',
    ]
  });
};

System-config.js:

/** Map relative paths to URLs. */
const map: any = {
  /* more code here */
  jsonwebtoken: 'vendor/jsonwebtoken',
};

/** User packages configuration. */
const packages: any = {
  /* more code here */
  jsonwebtoken:{
    defaultExtension: 'js',
    main: 'index.js'
  }
};

App Component:

import { Component } from '@angular/core';

@Component({
  moduleId: module.id,
  selector: 'app-selector',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.css']
})

export class AppComponent {

  constructor() {
  }

  doSomething() {
    /*
    How do I use jsonwebtoken here
    */
  }


}

Upvotes: 2

Views: 426

Answers (1)

grim_i_am
grim_i_am

Reputation: 3923

Why don't you try angular2-jwt:

https://github.com/auth0/angular2-jwt

npm install angular2-jwt --save

Upvotes: 1

Related Questions