title: Avoiding duplicate scripts in bundles & tree shaking
body: <p>So I'm just trying to go through the <a href="https://www.npmjs.com/package/webpack-bundle-analyzer" rel="nofollow noreferrer">webpack-bundle-analyzer</a> results looking for things that should be on a diet and understand the CLI build process more in depth (CLI v6.1.5, Angular v6.1.8) and improve our instance.</p>
  
  <p>I noticed that on just a general <code>ng build</code> when I go look through the vendor bundle I see; </p>
  
  <pre><code>var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
   * jQuery JavaScript Library v3.2.1
  </code></pre>
  
  <p>which is unfortunate as it's unminified as the whole jquery.js file at like 260k+, however I also find this in the scripts bundle;</p>
  
  <p><code>/*! jQuery v3.2.1 | (c)</code> which is the minified file version I would expect considering I have it declared explicitly in my scripts array in <code>angular.json</code></p>
  
  <p>So I figured if I moved it over to the <code>tsconfig.json</code> as a module path as;</p>
  
  <pre><code>"paths": {
          "jquery": ["./node_modules/jquery/dist/jquery.min.js"],
      }
  </code></pre>
  
  <p>Then it should pick up the min version and strip the other from vendor like I've done with others. Which it does, builds fine, I see the size difference, jquery.js is gone from the vendor bundle....but, I remember there's no typeroots on modules this way so when I go to init I get a crap ton of <code>error TS2304: Cannot find name '$'</code> errors. Which, I don't really want <code>import * as $ from 'jquery'</code> declarations all over if I can avoid it and also I've got a dependent in the same path on the <code>angular.json</code> of some jquery-ui library I've not used as;</p>
  
  <pre><code>"scripts": [
                "./node_modules/jquery/dist/jquery.min.js",
                "./vendor_scripts/jquery-ui/jquery-ui.min.js",
  .....
  </code></pre>
  
  <p>Where if I just omit the jquery.min.js path then I get <code>ReferenceError: $ is not defined</code> all over.</p>
  
  <p>So something in this build process I've inherited is out of line and I'm hoping someone can teach me something. How can I avoid the duplicate scripts to put the bundles on a diet, and how can I make sure I get my typings / ambient declarations respected the correct way? Cheers for reading either way!</p>