<?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: YeonJuan</title>
    <description>The latest articles on DEV Community by YeonJuan (@yeonjuan).</description>
    <link>https://dev.to/yeonjuan</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%2F494111%2F27c90b75-c10c-46a7-ac52-741c0a1e1b62.jpeg</url>
      <title>DEV Community: YeonJuan</title>
      <link>https://dev.to/yeonjuan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yeonjuan"/>
    <language>en</language>
    <item>
      <title>I created TypeScript ESLint Playground</title>
      <dc:creator>YeonJuan</dc:creator>
      <pubDate>Mon, 19 Oct 2020 12:56:17 +0000</pubDate>
      <link>https://dev.to/yeonjuan/i-created-typescript-eslint-playground-a4l</link>
      <guid>https://dev.to/yeonjuan/i-created-typescript-eslint-playground-a4l</guid>
      <description>&lt;p&gt;Hi there 👋.&lt;br&gt;
Sometimes I enjoyed contributing to the &lt;a href="https://github.com/typescript-eslint/typescript-eslint"&gt;typescript-eslint&lt;/a&gt; project. But it was tiring me to configure "typescript-eslint" for reproducing issues.&lt;/p&gt;

&lt;p&gt;So I created a &lt;a href="https://yeonjuan.github.io/typescript-eslint-demo"&gt;web playground&lt;/a&gt; for typescript eslint 🎉.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RSpAkzD2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/syflv8hzmwjmiyvxn08e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RSpAkzD2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/syflv8hzmwjmiyvxn08e.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
I think it would also be useful for someone trying to configure the "typescript-eslint" rule.&lt;br&gt;
Feel free to give it a little Star or Issue :)-&lt;a href="https://github.com/yeonjuan/typescript-eslint-demo"&gt;Github repo&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  How did It make?
&lt;/h1&gt;

&lt;p&gt;The biggest challenge was a bundling module that using node built-in modules (fs, path...)&lt;/p&gt;

&lt;p&gt;When bundling typescript-eslint and eslint with webpack, it throws errors because it cannot bundle NodeJS Built-In modules (e.g. ’fs’, ‘path’)..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR in ./node_modules/@eslint/eslintrc/lib/config-array-factory.js
Module not found: Error: Can't resolve 'fs' in '...project/node_modules/@eslint/eslintrc/lib'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, I must handle them, especially. There are two cases I should care about.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Module using NodeJS Built-Ins but unused on runtimes.&lt;/li&gt;
&lt;li&gt;Module using NodeJS Built-Ins and needed on runtimes.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Handing modules unused on runtimes
&lt;/h2&gt;

&lt;p&gt;For the first case, I can use &lt;a href="https://webpack.js.org/loaders/null-loader/"&gt;webpack null-loader&lt;/a&gt;. It allows us to bundle some modules with an empty module.&lt;/p&gt;

&lt;p&gt;We need to install null-loader&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install null-loader --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then added the loader to our webpack config. The webpack will load modules specified in &lt;code&gt;test&lt;/code&gt; as an empty module. By that, we can avoid webpack errors.&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="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;//...&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="sr"&gt;eslint&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="sr"&gt;.*&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="sr"&gt;cli-engine/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="c1"&gt;// ...&lt;/span&gt;
      &lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="na"&gt;use&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;null-loader&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;h2&gt;
  
  
  2. Handling modules used on runtimes
&lt;/h2&gt;

&lt;p&gt;In this case, The  &lt;a href="https://webpack.js.org/plugins/normal-module-replacement-plugin/"&gt;NormalModuleReplacementPlugin&lt;/a&gt; works. It allows us to replace some resources with custom resources. By it, I could replace modules with my custom ones.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;replacement module.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/modules/globby.js - custom module&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;sync&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./tsconfig.json&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;ul&gt;
&lt;li&gt;webpack.config.js
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;webpack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;webpack&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&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="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;webpack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NormalModuleReplacementPlugin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="sr"&gt;/globby/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// target module&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;src/modules/globby.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;// custom module&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;You can check all code on &lt;a href="https://github.com/yeonjuan/typescript-eslint-demo"&gt;github repo&lt;/a&gt;. Thanks for reading :)&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>eslint</category>
      <category>playground</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
