angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Install 3rd party library

Open maxime1992 opened this issue 10 years ago • 5 comments

  1. OS? Linux (Ubuntu 16.04)
  2. Ng Version : 0.0.39 Node : 5.11.1 OS : Linux x64

I'm trying to add @ngrx to my NG2 app.

I followed the 3rd party libs https://github.com/angular/angular-cli/wiki/3rd-party-libs but still can't figure out how I should do that.

If I do that :

const barrels: string[] = [
  // Angular specific barrels.
  '@angular/core',
  '@angular/common',
  '@angular/compiler',
  '@angular/http',
  '@angular/router',
  '@angular/platform-browser',
  '@angular/platform-browser-dynamic',
  '@ngrx/store',
  ...

(notice the line '@ngrx/store' that I added by hand)

and that :

System.config({
  map: {
    '@angular': 'vendor/@angular',
    'rxjs': 'vendor/rxjs',
    'main': 'main.js',
    '@ngrx': 'vendor/@ngrx'
  },
  packages: cliSystemConfigPackages
});

(notice the line '@ngrx': 'vendor/@ngrx' that I added by hand)

BUT, those lines are after that :

////////////////////////////////////////////////////////////////////////////////////////////////
/***********************************************************************************************
 * Everything underneath this line is managed by the CLI.
 **********************************************************************************************/

So I think I should put them somewhere here instead :

/***********************************************************************************************
 * User Configuration.
 **********************************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
   // here ?
};

/** User packages configuration. */
const packages: any = {
   // here ?
};

I just don't understand where to put it, any help on that would be nice :)

Thanks

maxime1992 avatar May 12 '16 13:05 maxime1992

I just updated the wiki and I think this section and this one could help.

Does it?

quentint avatar May 12 '16 15:05 quentint

In your system-config.ts file

/***********************************************************************************************
 * User Configuration.
 **********************************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
  '@ngrx': 'vendor/@ngrx'
};
// Thirdparty barrels.
  'rxjs',
  '@ngrx/store'

// Apply the CLI SystemJS configuration.
System.config({
  map: {
    '@angular': 'vendor/@angular',
    'rxjs': 'vendor/rxjs',
    'main': 'main.js',
    '@ngrx': 'vendor/@ngrx'
  },
  packages: _cliSystemConfig
});

Then in the angular-cli-build.js

module.exports = function(defaults) {
  return new Angular2App(defaults, {
    vendorNpmFiles: [
      'systemjs/dist/system-polyfills.js',
      'systemjs/dist/system.src.js',
      'zone.js/dist/*.js',
      'es6-shim/es6-shim.js',
      'reflect-metadata/*.js',
      'rxjs/**/*.js',
      '@angular/**/*.js',
      '@ngrx/**/*.js'
    ]
  });
};

That should get you going.

dancoto avatar May 13 '16 03:05 dancoto

@dcoto thanks for you help. I did try what you wrote and it's very similar to what I had. Yes it's working, but as I say in my initial question, I feel like there's something wrong as we are writing after those lines :

////////////////////////////////////////////////////////////////////////////////////////////////
/***********************************************************************************************
 * Everything underneath this line is managed by the CLI.
 **********************************************************************************************/

@quentint thank you too for your quick answer. Your update of the wiki did help a lot, it's working fine now by just updating the lines before those managed by the cli :

/***********************************************************************************************
 * User Configuration.
 **********************************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
    '@ngrx': 'vendor/@ngrx'
};

/** User packages configuration. */
const packages: any = {
    '@ngrx/store': {
        format: 'cjs',
        defaultExtension: 'js',
        main: 'index.js'
    },
};

// nothing as changed after that

Cheers !

maxime1992 avatar May 13 '16 06:05 maxime1992

I am also trying to install ngrx but I cannot find any system-config.ts files in my project to edit?

mangopop avatar Aug 17 '16 13:08 mangopop

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.