preboot / angular-webpack

A complete, yet simple, starter for Angular v2+ using webpack
MIT License
1.29k stars 557 forks source link

Cannot use Underscore #266

Closed nganlamsong closed 7 years ago

nganlamsong commented 7 years ago

I cannot use underscore in my project:

I tried to add 'import * as _ from 'underscore';' in vendor.ts but it no use! When I tried to run "npm run build", I got error message ""Can not find module 'underscore' "". Am I missing something? Please provide the correct way to use underscore! Thanks!

strictd commented 7 years ago

everyone forgets to install the underscore types library npm install \@types/underscore also import * as _ from 'underscore'; should go at the top of your *.component.ts files as needed. you should not need to import underscore in your vendor.ts file.

olingerc commented 7 years ago

@strictd could you please elaborate why underscore should not be in vendor.ts ? How do you decide what goes where?

strictd commented 7 years ago

It seems to boil down to what file your third party module is packed in when compiled. Think of vendor.js as the shared third party module pack for your main app.js and any lazy loaded packs.

it works with or without import 'underscore'; inside vendor.js .. Look at the file sizes of your output dist/js/*.js files running it both ways.

Foxandxss commented 7 years ago

I will kill vendor.ts soon, probably. Doesn't work well with lazy loading.