<?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: Vita</title>
    <description>The latest articles on DEV Community by Vita (@imciflam).</description>
    <link>https://dev.to/imciflam</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%2F477268%2F33b8c68f-ee1f-4829-992b-14206b6ada10.jpeg</url>
      <title>DEV Community: Vita</title>
      <link>https://dev.to/imciflam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imciflam"/>
    <language>en</language>
    <item>
      <title>Using aliases in webpack</title>
      <dc:creator>Vita</dc:creator>
      <pubDate>Tue, 29 Sep 2020 11:49:02 +0000</pubDate>
      <link>https://dev.to/imciflam/using-aliases-in-webpack-2cn0</link>
      <guid>https://dev.to/imciflam/using-aliases-in-webpack-2cn0</guid>
      <description>&lt;p&gt;Last thing you want to see in your project's imports is ugly stuff like this&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwo7hl9fdgexsz1gii0jo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwo7hl9fdgexsz1gii0jo.png" alt="pic" width="800" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because this is a feature I use with some frequency, but not frequently enough that I remember the pattern when I need it, I wrote this article as my own memo.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Change settings for webpack's config - using &lt;em&gt;eslint-import-resolver-alias&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  resolve: {
    alias: {
      '@ui': path.resolve(__dirname, 'src/components/ui'),
      '@shared': path.resolve(__dirname, 'src/shared'),
    },
    modules: [path.join(__dirname, 'src'), 'node_modules'],
    extensions: ['.js', '.jsx'],
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Change VSCode settings so Intellisense won't break
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "compilerOptions": {
    "allowSyntheticDefaultImports": false,
    "baseUrl": ".",
    "jsx": "react",
    "paths": {
      "@ui/*": ["./src/components/ui/*"],
      "@shared/*": ["./src/shared/*"]
    }
  },
  "exclude": ["node_modules"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Replace everything using a regexp.
Example:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/'.*/shared/g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;or, if there's a simpler case&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(\s)from(.*)shared/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(whitespace is important so it won't count in files which have a "from" ending)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;And then pretty it up with linter autofixer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Much better. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4uc2ifuvyc89zbx3lsf9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4uc2ifuvyc89zbx3lsf9.png" alt="pic" width="800" height="191"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webpack</category>
      <category>eslint</category>
      <category>aliases</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
