generator-angular2-library icon indicating copy to clipboard operation
generator-angular2-library copied to clipboard

Angular Universal (Server side rendering) - how use *.umd.js for node.js

Open kkaabbaa opened this issue 7 years ago • 4 comments

When I launch my application with angular universal i use this repo: https://github.com/evertonrobertoauler/cli-universal-demo

$ node dist/server.js 
~/api-lib/index.js:1
(function (exports, require, module, __filename, __dirname) { import { Component, Directive, ElementRef, Injectable, NgModule, Pipe } from '@angular/core';
                                                              ^^^^^^

SyntaxError: Unexpected token import

I see that when run build, lib is created in es2015 As in the file tsconfig.es5.json we have "module": "es2015"

But in the file api-lib.umd.js - this is what I need

In my application, I connect the library like this import {SampleModule, SampleService} from 'api-lib';

There is a solution in my project to make webpack compile into es5 In webpack.config.js

externals: [nodeExternals({
    whitelist: [
      /^api-lib/
    ]
  })],

But it seems to me not right, I do not understand how I can get my application to connect here is the api-lib.umd.js file when compiled Or should it automatically do this?

kkaabbaa avatar Jun 20 '17 07:06 kkaabbaa

@kkaabbaa — Is it possible to share your code? Thanks!

jvandemo avatar Jun 26 '17 03:06 jvandemo

@kkaabbaa

have the same issue how can I solve this?

crebuh avatar Sep 14 '17 08:09 crebuh

I used this post https://medium.com/@evertonrobertoauler/angular-4-universal-app-with-angular-cli-db8b53bba07d

and added

externals: [nodeExternals({
    whitelist: [
      /^api-lib/,
     /^some-lib/,
    ]
  })],

kkaabbaa avatar Sep 14 '17 17:09 kkaabbaa

+1

brunonm avatar Jan 24 '18 17:01 brunonm