<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Pontus Lundin</title>
    <description>The latest articles on DEV Community by Pontus Lundin (@hontas).</description>
    <link>https://dev.to/hontas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F219104%2F6871a08d-1270-40fd-a390-c8b0f6d32da9.jpeg</url>
      <title>DEV Community: Pontus Lundin</title>
      <link>https://dev.to/hontas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hontas"/>
    <language>en</language>
    <item>
      <title>Using Vite with linked dependencies</title>
      <dc:creator>Pontus Lundin</dc:creator>
      <pubDate>Fri, 12 Mar 2021 11:13:39 +0000</pubDate>
      <link>https://dev.to/hontas/using-vite-with-linked-dependencies-37n7</link>
      <guid>https://dev.to/hontas/using-vite-with-linked-dependencies-37n7</guid>
      <description>&lt;p&gt;&lt;strong&gt;TLDR&lt;/strong&gt;&lt;br&gt;
Use the Vite config option &lt;code&gt;optimizeDeps.exclude&lt;/code&gt; when working with linked local dependencies 👍&lt;/p&gt;

&lt;p&gt;The other day I was gonna take a look at a &lt;a href="https://github.com/sveltejs/svelte/issues/5989"&gt;Svelte issue&lt;/a&gt; and thought I'd try out &lt;a href="https://vitejs.dev/"&gt;Vite&lt;/a&gt; at the same time.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;I start by linking my fork of Svelte and run it in dev mode so it will automatically update.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# svelte-fork&lt;/span&gt;
npm &lt;span class="nb"&gt;link
&lt;/span&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my test project, I configure Vite to transpile svelte-files, which was really smooth since it supports rollup-plugins. Then I link Svelte and start it in dev mode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# test-project&lt;/span&gt;
npm &lt;span class="nb"&gt;link &lt;/span&gt;svelte
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I start making changes in my fork of Svelte and expect the changes to be reflected in the test-project but nothing happens. Inspecting the &lt;code&gt;node_modules&lt;/code&gt; folder shows that the changes are there but in the sources-panel of Chrome nothing has changed.&lt;/p&gt;

&lt;p&gt;I restart Vite but nothing changes.&lt;/p&gt;

&lt;p&gt;So I bring out the big guns and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; node_modules
npm &lt;span class="nb"&gt;install
&lt;/span&gt;npm &lt;span class="nb"&gt;link &lt;/span&gt;svelte
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;A simpler approach to this 👆 is to remove &lt;code&gt;node_modules/.vite&lt;/code&gt; where Vite keeps the pre-bundled files.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And finally, I can observe my changes. But this is not very smooth.&lt;/p&gt;

&lt;p&gt;Then I take a look at the Vite config documentation where I find the &lt;code&gt;optimizeDeps.exclude&lt;/code&gt; option that tells Vite which dependencies NOT to pre-bundle, and yes, we have a winner 🥳&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
  &lt;span class="na"&gt;optimizeDeps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;svelte&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And let me tell you - this works like a charm and I'm finally back to the smooth side of things 😎&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
