title: In npm/yarn workspaces, should packages consume src or dist
body: <p>I want to use a monorepo for our frontend app. We want to divide some react UI components into a package folder under &quot;/packages/ui-components&quot; and leave the app in an &quot;/apps/app&quot; folder and then have the app consume ui-components by importing it (simplified setup). We don't plan to release these packages to individual npm repos anytime soon, but just have the final app running.</p>
  <p>I'm starting to worry a bit about how we can have the best workflow, and for some reason I cannot find this in my research:</p>
  <p>Should the app consume the src-files from packages or instead compile each package to the dist folder and import only these?</p>
  <p>Workflow wise we would like working in different packages seamless, so if someone edits in a package we would like these changes to immediately show in the App.</p>
  <p>I see some pros and cons of using source-files compared to using a dist-output.</p>
  <p><strong>Pros of using src directly:</strong></p>
  <ul>
  <li>Better tree-shaking, as dependencies can be peer-dependencies and libraries that are used by multiple packages can be combined.</li>
  <li>Smaller final bundle size due to webpack having better access to original data like full dependency-tree and common functions etc.</li>
  <li>Faster development iterations with smaller projects as there's only one build and smart webpack could potentially only recompile a few changed files.</li>
  </ul>
  <p><strong>Pros of using dist:</strong></p>
  <ul>
  <li>More independent packages as they can contain their own build-pipeline.</li>
  <li>Will be easier to import as less peer-dependencies and special webpack-config is needed</li>
  <li>Ready to be published as a public npm package</li>
  <li>Possibly faster build-time as only changed packages and main-app needs to recompile on changes (I assume webpack can do cache, so maybe this doesnt matter much)</li>
  </ul>
  <p>I'm sure I'm missing a lot of details; setting up the good development flow is quiet complicated these days and I would like to make it as simple to use as possible for my colleagues..</p>
  <p><strong>TL;DR;</strong></p>
  <p>Should packages in a mono-repo build to their dist for others to consume, or is it better to import directly from src.</p>