<?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: nirtamir2</title>
    <description>The latest articles on DEV Community by nirtamir2 (@nirtamir2).</description>
    <link>https://dev.to/nirtamir2</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%2F629048%2F1b32f916-4544-4477-9ca4-fa356fea6d30.png</url>
      <title>DEV Community: nirtamir2</title>
      <link>https://dev.to/nirtamir2</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nirtamir2"/>
    <language>en</language>
    <item>
      <title>How to configure oh-my-zsh on Windows</title>
      <dc:creator>nirtamir2</dc:creator>
      <pubDate>Sat, 03 Jul 2021 14:40:49 +0000</pubDate>
      <link>https://dev.to/nirtamir2/how-to-configure-oh-my-zsh-in-windows-5cp2</link>
      <guid>https://dev.to/nirtamir2/how-to-configure-oh-my-zsh-in-windows-5cp2</guid>
      <description>&lt;p&gt;There are 2 major ways to install &lt;a href="https://ohmyz.sh/" rel="noopener noreferrer"&gt;oh-my-zsh&lt;/a&gt; in Windows: With WSL / without WSL.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp97wqn2eijigl6qtcfxq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp97wqn2eijigl6qtcfxq.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation with WSL
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://docs.microsoft.com/en-us/windows/wsl/" rel="noopener noreferrer"&gt;WSL&lt;/a&gt; (Windows Subsystem for Linux) is a Windows feature that lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a traditional virtual machine or dual-boot setup.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can use the WSL2 which is faster than v1. After the installation - you can install &lt;a href="https://ubuntu.com/" rel="noopener noreferrer"&gt;Ubuntu&lt;/a&gt; (a Linux distribution) from the &lt;a href="https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6" rel="noopener noreferrer"&gt;Windows app store&lt;/a&gt;. Just follow the &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/" rel="noopener noreferrer"&gt;official guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I tried it for a while. You get the benefit of full Linux distribution inside Windows. &lt;/p&gt;

&lt;h3&gt;
  
  
  Some things to notice
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You have 2 file systems. The subsystem files can be accessed differently via local network drive / command line. It's less convenient for me to get those files from the Linux system - instead of one single system. The paths are different.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You use your windows apps and install some command line packages in the Linux side. Your code is stored in the Linux environment.&lt;br&gt;
&lt;a href="https://code.visualstudio.com/blogs/2019/09/03/wsl2" rel="noopener noreferrer"&gt;VSCode&lt;/a&gt; and &lt;a href="https://www.jetbrains.com/help/idea/how-to-use-wsl-development-environment-in-product.html" rel="noopener noreferrer"&gt;Webstorm&lt;/a&gt; that are installed on your Windows can read/write your files from the Linux environment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Every package you want to access with your Linux system's command line - should be installed on the Linux system. So this make you install tools like git, Node.js, Yarn and global packages on the Linux side too. If you want to develop sometimes on windows and sometimes on Linux - you will get some duplications.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx6dfzsjnvotil41es94a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx6dfzsjnvotil41es94a.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I don't use WSL2 anymore
&lt;/h2&gt;

&lt;p&gt;I tried to use WSL2 for a while, but then I notice a major problem: my dev server did not notice file changes. Tools like nodemon, hot-module-replacement and fast refresh did not work. It turns out that there is a open issue:&lt;/p&gt;


&lt;div class="ltag_github-liquid-tag"&gt;
  &lt;h1&gt;
    &lt;a href="https://github.com/microsoft/WSL/issues/4739" rel="noopener noreferrer"&gt;
      &lt;img class="github-logo" alt="GitHub logo" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg"&gt;
      &lt;span class="issue-title"&gt;
        [WSL2] File changes made by Windows apps on Windows filesystem don't trigger notifications for Linux apps
      &lt;/span&gt;
      &lt;span class="issue-number"&gt;#4739&lt;/span&gt;
    &lt;/a&gt;
  &lt;/h1&gt;
  &lt;div class="github-thread"&gt;
    &lt;div class="timeline-comment-header"&gt;
      &lt;a href="https://github.com/SteveSandersonMS" rel="noopener noreferrer"&gt;
        &lt;img class="github-liquid-tag-img" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F1101362%3Fv%3D4" alt="SteveSandersonMS avatar"&gt;
      &lt;/a&gt;
      &lt;div class="timeline-comment-header-text"&gt;
        &lt;strong&gt;
          &lt;a href="https://github.com/SteveSandersonMS" rel="noopener noreferrer"&gt;SteveSandersonMS&lt;/a&gt;
        &lt;/strong&gt; posted on &lt;a href="https://github.com/microsoft/WSL/issues/4739" rel="noopener noreferrer"&gt;&lt;time&gt;Dec 06, 2019&lt;/time&gt;&lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag-github-body"&gt;
      &lt;p&gt;WSL2 is &lt;strong&gt;really close&lt;/strong&gt; to being a perfect runtime environment for server apps being developed in Windows. Great job! One missing feature however is breaking a core part of the developer flow.&lt;/p&gt;
&lt;p&gt;For sources stored on the Windows filesystem, any changes made by Windows applications such as Visual Studio do not trigger any file change notifications as far as Linux apps are concerned. This means that all "live rebuild"-type tools don't work (examples: &lt;code&gt;webpack --watch&lt;/code&gt;, &lt;code&gt;jekyll --interactive&lt;/code&gt;, and &lt;a href="https://tilt.dev/" rel="nofollow noopener noreferrer"&gt;Tilt.dev&lt;/a&gt;) when running under WSL2. This unfortunately renders many modern dev workflows unviable.&lt;/p&gt;
&lt;p&gt;Notes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I strongly expect this is already a known issue &lt;a href="https://github.com/microsoft/WSL/issues/1956#issuecomment-491266167" rel="noopener noreferrer"&gt;as hinted here&lt;/a&gt;. However I was unable to find any open GitHub issue that specifically tracks this. #1956 is about a different scenario, #4064 isn't specifically about change notifications, #4224 is closed, #4293 doesn't fix it.&lt;/li&gt;
&lt;li&gt;I'm aware the WSL team suggests that with WSL2 it's good to store your application sources inside the Linux filesystem instead of the Windows one. However I don't think that's a viable solution since the whole point of WSL (for me) is to be able to use Windows-based editors such as full VS with a Linux dev environment. If it was sufficient to use Linux-based editors, I'd just use Mac/Linux as my actual OS and would have no need for WSL.&lt;/li&gt;
&lt;li&gt;This did work great on WSL1&lt;/li&gt;
&lt;li&gt;Changing &lt;code&gt;fs.inotify.max_user_watches&lt;/code&gt; doesn't affect this, since the issue is about changes originating on the Windows side.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
&lt;span class="octicon octicon-link"&gt;&lt;/span&gt;Bug report template&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Your Windows build number:  10.0.19033.1&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What you're doing and what's happening:&lt;/p&gt;
&lt;p&gt;This applies to all tools that listen for file change notifications, but as an example take &lt;code&gt;webpack&lt;/code&gt;. Repro steps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In your Windows filesystem, create an empty directory (example: &lt;code&gt;c:\repro&lt;/code&gt;), and then add &lt;a href="https://gist.github.com/SteveSandersonMS/b6e1e2db31ba12fd0c7ae288dc61660f" rel="noopener noreferrer"&gt;these three files to it&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;In a WSL2 Ubuntu 18.04 environment, install Node and NPM: &lt;code&gt;sudo apt-get install nodejs npm&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Still in WSL2, go into the directory from earlier: &lt;code&gt;cd /mnt/c/repro&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Restore NPM dependencies: &lt;code&gt;npm i&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run Webpack in watch mode: &lt;code&gt;npm run build:watch&lt;/code&gt;. Wait a few seconds until it completes the first build. It will now be waiting for further changes to your source files.&lt;/li&gt;
&lt;li&gt;In a Windows application (e.g., Notepad or Visual Studio), open &lt;code&gt;c:\repro\index.js&lt;/code&gt; and save some change to it. For example, change &lt;code&gt;'Hello, world'&lt;/code&gt; to &lt;code&gt;'Hello, world 2'&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What's wrong / what should be happening instead:&lt;/p&gt;
&lt;p&gt;Expected behavior: Webpack should see the change and rebuild. That is, you'll see it log information about another build, and the output in &lt;code&gt;dist/bundle.js&lt;/code&gt; will be updated.&lt;/p&gt;
&lt;p&gt;Actual behavior: Webpack doesn't respond at all, because there's no file change notification.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Finally&lt;/strong&gt; I understand that the fix for this is likely to be "&lt;em&gt;add file watch capabilities to the Plan9 server&lt;/em&gt;", and you may feel this is already being tracked by #4064. However #4064 describes a more obscure symptom of this missing feature and makes it sound like an intermittent issue. What I'm reporting here is not intermittent at all, and is a pretty mainstream scenario (using tools like &lt;code&gt;webpack --watch&lt;/code&gt;). Thanks!&lt;/p&gt;

    &lt;/div&gt;
    &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/microsoft/WSL/issues/4739" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Some of those problems have workaround with polling instead of file watching. I try the polling approach with vite, but the experience was poor compared to vite regular fast refresh. This was &lt;strong&gt;BLOCKER&lt;/strong&gt; issue for me so I removed WSL2.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation without WSL2
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Install Cygwin
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Cygwin is a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This part of the post is based on &lt;a href="https://dev.to/zinox9"&gt;zinox9&lt;/a&gt;'s excellent &lt;a href="https://dev.to/zinox9/installing-zsh-on-windows-37em"&gt;post&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download Cygwin from &lt;a href="https://cygwin.com/install.html" rel="noopener noreferrer"&gt;it's website&lt;/a&gt; and run the installer.&lt;/li&gt;
&lt;li&gt;Make Sure to Let the installer install at &lt;code&gt;C:\cygwin64&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;For Download site Select Any URL , Click Add&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;STOP&lt;/strong&gt; at packages screen, search &lt;strong&gt;wget&lt;/strong&gt; expand &lt;code&gt;All&lt;/code&gt; under &lt;code&gt;Web&lt;/code&gt; select latest version of it under &lt;code&gt;bin&lt;/code&gt; of &lt;code&gt;wget&lt;/code&gt; no need to select Source. Then Continue.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5tsy6ykymjs1hs1zdvd6.png" alt="Cygwin wget Screen"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Finish Installing and launch the Terminal.&lt;br&gt;
We are going to use Cygwin to Install Some Packages that will help to use Linux System on Windows. We will install &lt;strong&gt;apt-cyg&lt;/strong&gt; which will work like &lt;code&gt;apt-get&lt;/code&gt; and also install many other packages too like &lt;a href="https://www.vim.org/" rel="noopener noreferrer"&gt;vim&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Run The following to download &lt;code&gt;apt-cyg&lt;/code&gt; with &lt;code&gt;wget&lt;/code&gt;. Note you can prompt to install &lt;code&gt;gdb&lt;/code&gt;, &lt;code&gt;vim&lt;/code&gt; or &lt;code&gt;dos2unix&lt;/code&gt; if you want to use them or just remove them, you can install even more packages of your choice if you wish !&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget rawgit.com/transcode-open/apt-cyg/master/apt-cyg
install apt-cyg /bin
apt-cyg install zsh git gdb dos2unix openssh chere vim
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;ul&gt;
&lt;li&gt;If you want your home folder to be your user's folder, you need to edit &lt;code&gt;cygwin64/etc/nsswitch.conf&lt;/code&gt;. You can do this in the text editor you just downloaded, or type &lt;code&gt;explorer /etc&lt;/code&gt; to open the root directory to edit the file. Add this line to the bottom: &lt;code&gt;db_home: windows&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Setting Up oh-my-zsh
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Install oh-my-zsh from it's &lt;a href="https://ohmyz.sh/#install" rel="noopener noreferrer"&gt;website&lt;/a&gt; or &lt;a href="https://github.com/ohmyzsh/ohmyzsh#basic-installation" rel="noopener noreferrer"&gt;github&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Add plugins - 
I use 3 plugins for my dev environment:

&lt;ul&gt;
&lt;li&gt;git (from oh-my-zsh plugins)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/chrisands/zsh-yarn-completions" rel="noopener noreferrer"&gt;zsh-yarn-completions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/zsh-users/zsh-autosuggestions" rel="noopener noreferrer"&gt;zsh-autosuggestions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;So my ~/.zshrc file looks like &lt;code&gt;plugins=(git zsh-yarn-completions zsh-autosuggestions)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I also add alias for open to the windows explorer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias open=explorer.exe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Integrate with terminals
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Windows terminal
&lt;/h4&gt;

&lt;p&gt;Edit your &lt;code&gt;settings.json&lt;/code&gt; with the following profile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;"defaultProfile"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"{61c54bbd-c2c6-5271-96e7-009a87ff44ba}"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"profiles"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; 
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"defaults"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"list"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; 
        &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"background"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"#282C34"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"commandline"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"C:/cygwin64/bin/bash.exe /bin/xhere /bin/zsh"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"cursorColor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"#FFFFFF"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"foreground"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"#DCDFE4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"guid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"{61c54bbd-c2c6-5271-96e7-009a87ff44ba}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"hidden"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Work"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"startingDirectory"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"C://devl//work"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  VSCode
&lt;/h4&gt;

&lt;p&gt;In &lt;code&gt;settings.json&lt;/code&gt; add the following settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"terminal.integrated.shell.windows"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"C:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;Cygwin64&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;bin&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;bash.exe"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"terminal.integrated.shellArgs.windows"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"/bin/xhere"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/bin/zsh"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Webstorm
&lt;/h4&gt;

&lt;p&gt;Add &lt;code&gt;C:/cygwin64/bin/bash.exe /bin/xhere /bin/zsh&lt;/code&gt; to Shell path setting&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpe0arhy351k5htmtfi8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpe0arhy351k5htmtfi8.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I highly recommend using oh-my-zsh in your dev environment for better auto-completions in your terminal. Because of file watching issue with WSL2, I use Cygwin to help with the zsh installation.&lt;br&gt;
If you know some improvements to this setup - feel free to comment about.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9wzvuw4kb9mfz3ldncdu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9wzvuw4kb9mfz3ldncdu.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Using Vite with React</title>
      <dc:creator>nirtamir2</dc:creator>
      <pubDate>Mon, 10 May 2021 19:31:28 +0000</pubDate>
      <link>https://dev.to/nirtamir2/using-vite-with-react-55go</link>
      <guid>https://dev.to/nirtamir2/using-vite-with-react-55go</guid>
      <description>&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;It all started when I had to configure another simple thing in webpack (4.x). It's a SPA monorepo app written with React, TypeScript, and styled-components. It takes ~2 minutes to start the dev server for the UI. Which is kind of frustrating. The fast-refresh is also not that fast, and you can see a notable delay between updates.&lt;/p&gt;

&lt;p&gt;Understanding that migration to managed SSR solutions like Next.js takes more time, effort, and a stiff learning curve for my team, I had an opportunity to integrate one of the new shiny bundle tools that use esbuild + ES modules (ESM) with almost not config. &lt;a href="https://github.com/evanw/esbuild" rel="noopener noreferrer"&gt;esbuild&lt;/a&gt; is "An extremely fast JavaScript bundler and minifier". EXTREMELY FAST:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4e5nedaff56aofu7bso3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4e5nedaff56aofu7bso3.png" alt="esbuild is fast"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/evanw/esbuild" rel="noopener noreferrer"&gt;Why it's so fast?&lt;/a&gt; because it's written in go and does a lot of optimizations.&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules" rel="noopener noreferrer"&gt;ES modules&lt;/a&gt; is a new browser feature that enables to &lt;strong&gt;natively&lt;/strong&gt; load modules - meaning no need to bundle everything in one giant bundle. We can split the code into smaller modules and load them as needed. This helps avoid unnecessary work and stay fast no matter how big the project grows.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2wmzp2963awd90k07c5e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2wmzp2963awd90k07c5e.png" alt="regular server"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmdnuyln9kx308m1ykr1j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmdnuyln9kx308m1ykr1j.png" alt="esm dev server"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I already played with those tools with some little demos at home for my learning. But now I had to find a way to use them in the production app in my company.&lt;/p&gt;
&lt;h2&gt;
  
  
  Snowpack vs Vite vs WMR
&lt;/h2&gt;

&lt;p&gt;It did not take a lot of time to choose the tool. Currently, there are 3 major bundlers powered by ESM &lt;a href="https://esbuild.github.io/" rel="noopener noreferrer"&gt;&lt;/a&gt;- &lt;a href="http://vitejs.dev/" rel="noopener noreferrer"&gt;vite&lt;/a&gt;, &lt;a href="https://www.snowpack.dev/" rel="noopener noreferrer"&gt;snowpack&lt;/a&gt;, and &lt;a href="https://github.com/preactjs/wmr" rel="noopener noreferrer"&gt;wmr&lt;/a&gt;. From the first glance - all of them look promising and I did not care about their internals as long as I don't need to touch them.&lt;/p&gt;

&lt;p&gt;I chose Vite for 2 main reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vite handles monorepos better (snowpack work &lt;a href="https://github.com/snowpackjs/snowpack/discussions/938" rel="noopener noreferrer"&gt;is still in progress&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;wmr does not have &lt;a href="https://github.com/preactjs/wmr/issues/128" rel="noopener noreferrer"&gt;error overlay / SVGR support&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I think that soon - those issues will be resolved, but for now, I bet on vite.&lt;/p&gt;

&lt;p&gt;For deeper comparison, you can look at &lt;a href="https://vitejs.dev/guide/comparisons.html#snowpack" rel="noopener noreferrer"&gt;this article&lt;/a&gt; from vite's documentation, but also notice that some of the latest snowpack progression does not mention there.&lt;/p&gt;

&lt;p&gt;One of the benefits I like about those tools is that they require less configuration to write - they all support all the major workarounds out of the box. So you don't tie into complex configs like in webpack. You don't need to config anything to support TypeScript, React, Babel, manage public or static assets, fast-refresh, dynamic imports, etc... This makes migration easy if we will want.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The code you don't have to write - is the code that doesn't lift you from migration. It's not a major bet if you don't have to risk much.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  The journey to configure vite
&lt;/h2&gt;

&lt;p&gt;Looking at the example at vite-create-app &lt;a href="https://github.com/vitejs/vite/tree/main/packages/create-app/template-react-ts" rel="noopener noreferrer"&gt;ts-react template&lt;/a&gt; I was able to configure 80% of the work.&lt;/p&gt;

&lt;p&gt;But I already know that it's one of those cases that those last 20% take more time to configure than the first 80%. Those tiny bugs / unmatched stuff you have to fix. Some of them are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I had to fix some unrelated TypeScript type definitions. I don't know why do we have code like &lt;code&gt;const f = &amp;lt;T,&amp;gt;() =&amp;gt; return f2&amp;lt;T&amp;gt;()&lt;/code&gt; and why vite (or it may be a rollup / TypeScript issue?) struggles to transpile it - I convert this, for now, to &lt;code&gt;&amp;lt;T extends unknown&amp;gt;&lt;/code&gt; which is equivalent to make it work.&lt;/li&gt;
&lt;li&gt;We already have configured path aliases with &lt;a href="https://github.com/dividab/tsconfig-paths-webpack-plugin#readme" rel="noopener noreferrer"&gt;webpack and tsconfig&lt;/a&gt; - so I wanted to keep that behavior. Luckily we have the &lt;a href="https://github.com/aleclarson/vite-tsconfig-paths#readme" rel="noopener noreferrer"&gt;vite-tsconfig-paths&lt;/a&gt; exactly for that. It worked well. I could also try using the &lt;a href="https://vitejs.dev/config/#resolve-alias" rel="noopener noreferrer"&gt;alias&lt;/a&gt; for that.&lt;/li&gt;
&lt;li&gt;Instead of &lt;a href="https://github.com/gregberge/svgr/tree/main/packages/webpack" rel="noopener noreferrer"&gt;webpack svgr&lt;/a&gt; - vite has a community plugin &lt;a href="https://github.com/pd4d10/vite-plugin-svgr#readme" rel="noopener noreferrer"&gt;vite-plugin-svgr&lt;/a&gt;. Looking at its &lt;a href="https://github.com/pd4d10/vite-plugin-svgr/blob/main/src/index.ts" rel="noopener noreferrer"&gt;source code&lt;/a&gt; I can tell that it does the work as needed. In the future, I may want to add more &lt;a href="https://react-svgr.com/docs/options/" rel="noopener noreferrer"&gt;SVGR options&lt;/a&gt; (currently for custom colors we use css &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentcolor_keyword" rel="noopener noreferrer"&gt;currentColor&lt;/a&gt; property), so I may contribute it or create a similar plugin. NOTE: vite bundles the static svg in addition to assets even if you use vite-plugin-svgr. So many useless files will be generated. This is a minor issue that can be unnoticeable. I created a script for deleting those files (it has 0 impacts on the bundle because the client does not download those chunks).&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Vite docs &lt;a href="https://vitejs.dev/guide/features.html#client-types" rel="noopener noreferrer"&gt;recommended&lt;/a&gt; specifying &lt;code&gt;vite/client&lt;/code&gt; types in &lt;code&gt;tsconfig.json&lt;/code&gt;. Before we did not explicitly specify this property - so we have to include other needed types like jest and node&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"compilerOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"types"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"vite/client"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Issues with 3rd party libraries
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Small &lt;a href="https://github.com/tannerlinsley/react-query/issues/1936" rel="noopener noreferrer"&gt;issue&lt;/a&gt; with &lt;a href="https://react-query.tanstack.com/" rel="noopener noreferrer"&gt;react-query&lt;/a&gt; devtools that solved by changing to a different minor version. But it's more an &lt;a href="https://github.com/vitejs/vite/issues/1676#issuecomment-766302418" rel="noopener noreferrer"&gt;issue with the library&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/remarkjs/react-markdown" rel="noopener noreferrer"&gt;react-markdown&lt;/a&gt; v4 also has &lt;a href="https://github.com/remarkjs/react-markdown/issues/492" rel="noopener noreferrer"&gt;an issue&lt;/a&gt; using &lt;code&gt;process.cwd&lt;/code&gt; internally. I upgraded to v5 and the problem is gone. It seems that like in webpack 5 - you won't get and node.js polyfills with vite.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now for the harder problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Some of our components depend on &lt;code&gt;process.env.NODE_ENV&lt;/code&gt;. Our old webpack config uses &lt;a href="https://webpack.js.org/plugins/define-plugin/" rel="noopener noreferrer"&gt;define-plugin&lt;/a&gt; to replace them with their node.js env values. So I specify them with &lt;a href="https://vitejs.dev/config/#define" rel="noopener noreferrer"&gt;define&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;define&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;process.env.NODE_ENV&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&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;/li&gt;
&lt;li&gt;
&lt;p&gt;Some third-party libraries like &lt;a href="https://github.com/plouc/nivo" rel="noopener noreferrer"&gt;nivo&lt;/a&gt; for graphs use internally Node.js specific &lt;code&gt;global&lt;/code&gt; keyword (&lt;a href="https://github.com/plouc/nivo/blob/99b520e9621e77472b8c922d85a0fcd7bc5e00cc/packages/network/src/props.js#L87" rel="noopener noreferrer"&gt;here&lt;/a&gt;). But ES modules do not support it - and we get a Reference not found error for &lt;code&gt;global&lt;/code&gt; variable. What vite tries to do is to convert them to be ESM - and run them in the browser. But the browser does not know what global is - so it fails. At first, I try to handle this in &lt;code&gt;vite.config.ts&lt;/code&gt; with define - setting &lt;code&gt;global: {}&lt;/code&gt; . But doing so created a problem with &lt;code&gt;import GlobalStyles from "./global.style"&lt;/code&gt; then converted to be unwanted &lt;code&gt;import GlobalStyles from "./{}.style"&lt;/code&gt; . So until nivo will upgrade to ES-modules - I hacked that global variable by pre-load in &lt;code&gt;index.html&lt;/code&gt; like&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;window.global = &lt;span class="si"&gt;{}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"./src/index.tsx"&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Env variables
&lt;/h2&gt;

&lt;p&gt;The next thing I had to handle is the env variables. vite put the env variables inside &lt;code&gt;import.meta.env&lt;/code&gt; (did you know &lt;code&gt;import.meta&lt;/code&gt; is &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta" rel="noopener noreferrer"&gt;in the spec&lt;/a&gt; + &lt;a href="https://nodejs.org/api/esm.html#esm_import_meta" rel="noopener noreferrer"&gt;node.js&lt;/a&gt; compatible?). Like next.js - if you want to expose them to the client-side you can use the &lt;code&gt;VITE_APP_YOUR_VARIABLE_NAME&lt;/code&gt; - which is nice. For TypeScript users - vite docs encourage to add to &lt;code&gt;tsconfig.json&lt;/code&gt;'s &lt;code&gt;compilerOptions&lt;/code&gt; with &lt;code&gt;types:["vite/client"]&lt;/code&gt; . But explicit writing types entry - you lose your jest, testing-library and node typings library supports. So you have to manually specify them too. You can now get vite typings - but they are still missing your env variables types. You can declare them like &lt;a href="https://stackoverflow.com/questions/66039933/typescript-types-for-import-meta-env" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I wonder it's better to just use dotenv + env variables that like I did with define?&lt;/p&gt;

&lt;p&gt;It makes stuff simplified.&lt;/p&gt;

&lt;h2&gt;
  
  
  Jest
&lt;/h2&gt;

&lt;p&gt;I had a problem with our tests with the &lt;code&gt;ts-jest&lt;/code&gt; preset that did not understand what &lt;code&gt;import.meta&lt;/code&gt; is. So I kept using &lt;code&gt;process.env&lt;/code&gt; in our code instead of &lt;code&gt;import.meta&lt;/code&gt;. This may not be a concern for you because it looks like vite is planning to create its own &lt;a href="https://github.com/vitejs/vite/issues/1149" rel="noopener noreferrer"&gt;jest preset&lt;/a&gt; to solve this problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bundle analyze
&lt;/h2&gt;

&lt;p&gt;In our "old" build system - I configured &lt;a href="https://github.com/webpack-contrib/webpack-bundle-analyzer" rel="noopener noreferrer"&gt;webpack-bundle-analyze&lt;/a&gt; to inspect bundle chunks and understand what it made of. I added &lt;a href="https://github.com/btd/rollup-plugin-visualizer" rel="noopener noreferrer"&gt;rollup-bundle-visualyzer&lt;/a&gt; instead (although there is &lt;a href="https://github.com/vitejs/vite/issues/898" rel="noopener noreferrer"&gt;an issue&lt;/a&gt; that the reported size is not correct).&lt;/p&gt;

&lt;h2&gt;
  
  
  The final &lt;code&gt;vite.config.ts&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;reactRefresh&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@vitejs/plugin-react-refresh&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;bundleVisualizer&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rollup-plugin-visualizer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vite&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;svgr&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vite-plugin-svgr&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;tsconfigPaths&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vite-tsconfig-paths&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getBundleVisualizerPlugin&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nf"&gt;bundleVisualizer&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;treemap&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// or sunburst&lt;/span&gt;
            &lt;span class="na"&gt;open&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;gzipSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;brotliSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}),&lt;/span&gt;
        &lt;span class="na"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;enforce&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;post&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="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Plugin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// https://vitejs.dev/config/&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nf"&gt;reactRefresh&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="nf"&gt;svgr&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="nf"&gt;tsconfigPaths&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BUNDLE_ANALYZE&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;getBundleVisualizerPlugin&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;define&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="s2"&gt;process.env.NODE_ENV&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&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;ul&gt;
&lt;li&gt;I will change the &lt;code&gt;as Plugin&lt;/code&gt; type assertion when &lt;a href="https://github.com/DefinitelyTyped/DefinitelyTyped/pull/51923" rel="noopener noreferrer"&gt;my PR&lt;/a&gt; to &lt;code&gt;@types/rollup-bundle-visualyzer&lt;/code&gt; will be merged&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;All the struggle to configure vite since the moment I decided until my PR merged took one day. Now we have a fast development environment for improved productivity. I'm sure that not all 3rd party libraries are compatible with vite. But things are getting better. The tech world evolves and I hope that library authors will eventually supply maintain ESM compatible build.&lt;/p&gt;

&lt;p&gt;My conclusion is that if you won't need SSR (which &lt;a href="https://vitejs.dev/guide/ssr.html" rel="noopener noreferrer"&gt;experimentally supported in vite&lt;/a&gt;), I encourage you to try vite / other ESM build tools. It will make your dev environment really fast. Start with the &lt;a href="http://vitejs.dev/" rel="noopener noreferrer"&gt;docs&lt;/a&gt;, Skim &lt;a href="https://github.com/vitejs/awesome-vite" rel="noopener noreferrer"&gt;https://github.com/vitejs/awesome-vite&lt;/a&gt; and look at the open issues too. It will make your dev environment really fast.&lt;/p&gt;

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