<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
  <title>BigBinary Blog: npm</title>
  <subtitle>Deep technical writing on Ruby on Rails, performance, scaling, monitoring and engineering.</subtitle>
  <link rel="self" type="application/atom+xml" href="https://www.bigbinary.com/blog/categories/npm/feed.xml"/>
  <link rel="alternate" type="text/html" href="https://www.bigbinary.com/blog/categories/npm"/>
  <id>https://www.bigbinary.com/blog/categories/npm</id>
  <updated>2024-06-11T00:00:00.000Z</updated>
  <author>
    <name>BigBinary</name>
    <uri>https://www.bigbinary.com/</uri>
  </author>
  <icon>https://www.bigbinary.com/favicon.ico</icon>
  <logo>https://www.bigbinary.com/images/bigbinary_square_big_logo.png</logo>
  <rights>Copyright 2024 Big Binary LLC</rights>
  <generator uri="https://nextjs.org">Next.js</generator>
  <entry>
      <title type="text"><![CDATA[How we build, release and maintain frontend packages]]></title>
      <link rel="alternate" type="text/html" href="https://www.bigbinary.com/blog/build-release-frontend-packages"/>
      <link rel="enclosure" type="image/jpeg" href="https://www.bigbinary.com/blog/images/social_preview_images/neeto_build_release.jpg"/>
      <id>https://www.bigbinary.com/blog/build-release-frontend-packages</id>
      <published>2024-06-11T00:00:00.000Z</published>
      <updated>2024-06-11T00:00:00.000Z</updated>
      <author>
        <name>Farhan CK</name>
        <uri>https://www.bigbinary.com/blog/authors/farhanlatheef</uri>
      </author>
      <category term="JavaScript"/>
      <category term="ReactJS"/>
      <category term="npm"/>
      <media:thumbnail url="https://www.bigbinary.com/blog/images/social_preview_images/neeto_build_release.jpg" width="1200" height="627"/>
      <summary type="text"><![CDATA[Here at neeto, we build and manage a lot of products. Each product has its team. However, ensuring consistent design and functionalities across these products poses a significant challenge. To aid...]]></summary>
      <content type="html" xml:base="https://www.bigbinary.com/blog/build-release-frontend-packages"><![CDATA[<p>Here at <a href="https://www.neeto.com/">neeto</a>, we build and manage a
<a href="https://blog.neeto.com/p/neeto-products-and-people">lot of products</a>. Each
product has its team. However, ensuring consistent design and functionalities
across these products poses a significant challenge. To aid our product teams in
focusing on their core business logic, we've organized common functionalities
into separate packages.</p>
<p>In this blog, we'll look into how we build, release, and maintain these packages
to support our product development cycles. Let's take a look at some of these
key packages.</p>
<h3>neeto-cist</h3>
<p><a href="https://github.com/bigbinary/neeto-cist">neeto-cist</a> contains essential pure
utility functions and forms the backbone of our development framework.</p>
<h3>neeto-ui</h3>
<p><a href="https://github.com/bigbinary/neeto-ui">neeto-ui</a> is the foundational design
structure for our Neeto products. It contains basic-level components like
Buttons, Input fields, etc.</p>
<h3>neeto-molecules</h3>
<p>Built on top of <code>neeto-ui</code>, the <code>neeto-molecules</code> package houses reusable UI
elements like a login page, settings page, sidebars etc. It simplifies the
creation of consistent user experiences across Neeto products.</p>
<h3>neeto-commons</h3>
<p><code>neeto-commons</code> store crucial elements such as initializers, constants, hooks
and configurations shared across our entire product range. We wrote in great
detail about the
<a href="https://www.bigbinary.com/blog/neeto-commons-frontend">challenges we faced while building neeto-commons</a>.</p>
<p>Let's look at how we build, release, and maintain these packages.</p>
<h2>Build</h2>
<p>In general we use <a href="https://babeljs.io/">Babel</a> to transpile and
<a href="https://rollupjs.org">Rollup</a> to bundle with some exceptions.</p>
<p>Let's look at our standard build configuration.</p>
<pre><code class="language-js">import peerDepsExternal from &quot;rollup-plugin-peer-deps-external&quot;;
import svgr from &quot;@svgr/rollup&quot;;
import babel from &quot;@rollup/plugin-babel&quot;;
import resolve from &quot;@rollup/plugin-node-resolve&quot;;
import alias from &quot;@rollup/plugin-alias&quot;;
import json from &quot;@rollup/plugin-json&quot;;
import commonjs from &quot;@rollup/plugin-commonjs&quot;;
import styles from &quot;rollup-plugin-styles&quot;;
import aliases from &quot;./aliases&quot;;

export default {
  input: {
    Component1: &quot;src/components/Component1&quot;,
    Component2: &quot;src/components/Component2&quot;,
    //... rest of the entry points
  },
  output: [&quot;esm&quot;, &quot;cjs&quot;].map(format =&gt; ({
    format,
    sourcemap: true,
    //... other options
  })),
  plugins: [
    // To automatically externalize peerDependencies in a Rollup bundle.
    peerDepsExternal(),
    // Inline any svg files
    svgr(),
    // To integrate Rollup and Babel.
    babel({
      exclude: &quot;node_modules/**&quot;,
      babelHelpers: &quot;runtime&quot;,
    }),
    // To use third party modules from node_modules
    resolve({ extensions: [&quot;.js&quot;, &quot;.jsx&quot;, &quot;.svg&quot;] }),
    // To define aliases while bundling package.
    alias({ entries: aliases }),
    // To convert .json files to ES6 modules.
    json(),
    // To convert CommonJS modules to ES6.
    commonjs(),
    // Handle styles
    styles({
      minimize: true,
      extensions: [&quot;.css&quot;, &quot;.scss&quot;, &quot;.min.css&quot;],
    }),
  ],
};
</code></pre>
<p>When dealing with multiple entry points, passing an array of <code>input</code> is a common
mistake people make. The problem with an <code>input</code> array is that it will be
duplicated if there is shared code. So, the best approach here is to pass a
key-value object. This way, Rollup will create separate files for shared code
and reuse them everywhere.</p>
<p>Looking at the <code>output</code>, notice that we built it for CommonJS and ECMAScript.
Even though we don't have any Node.js projects (we are mainly a Rails company),
we still need the CommonJS format to run Jest tests and some scripts for build
and automation purposes.</p>
<p>When using Babel to transpile and Rollup to bundle, we ran into some
configuration pain points.
<a href="https://www.npmjs.com/package/@rollup/plugin-babel"><code>@rollup/plugin-babel</code></a>
plugin made the configuration far easier.
<a href="https://www.npmjs.com/package/@svgr/rollup"><code>@svgr/rollup</code></a> converts normal svg
files to react components.
<a href="https://www.npmjs.com/package/rollup-plugin-peer-deps-external"><code>rollup-plugin-peer-deps-external</code></a>
automatically externalizes peer dependencies, keeping the bundle lean. Even
though we don't have any CommonJS modules, it's better to add
<a href="https://www.npmjs.com/package/@rollup/plugin-commonjs"><code>@rollup/plugin-commonjs</code></a>
so that if there is any deep in dependency rabbit hole.</p>
<p>Above is a simplified version of the Rollup configuration we use on
<code>neeto-cist</code>, <code>neeto-ui</code> and <code>neeto-molecules</code>. We took a much simpler approach
when building <code>neeto-commons</code>. The reason for abandoning bundling for
<code>neeto-commons</code> is that within this package, we have a variety of commonly used
elements, such as components, hooks, initializers, constants, utils, etc., each
with varying sizes and dependency requirements. If the host project only wants
to use a few simple util functions, we don't want them to be served with the
entire bundle and need to install lots of dependencies.</p>
<p>Instead of serving everything from the root <code>index.js</code>, we use
<a href="https://webpack.js.org/guides/package-exports/"><code>exports</code></a> field in the
<code>package.json</code> to specify which files can be imported by the host project. Below
is a sample of our exports.</p>
<pre><code class="language-json">&quot;exports&quot;: {
  &quot;./react-utils&quot;: {
    &quot;import&quot;: &quot;./react-utils/index.js&quot;,
    &quot;require&quot;: &quot;./cjs/react-utils/index.js&quot;,
    &quot;types&quot;: &quot;./react-utils.d.ts&quot;
  },
  &quot;./react-utils/*&quot;: {
    &quot;import&quot;: &quot;./react-utils/*&quot;,
    &quot;require&quot;: &quot;./cjs/react-utils/*&quot;,
    &quot;types&quot;: &quot;./react-utils.d.ts&quot;
  },
  &quot;./utils&quot;: {
    &quot;import&quot;: &quot;./utils/index.js&quot;,
    &quot;require&quot;: &quot;./cjs/utils/index.js&quot;,
    &quot;types&quot;: &quot;./utils.d.ts&quot;
  },
  &quot;./utils/*&quot;: {
    &quot;import&quot;: &quot;./utils/*&quot;,
    &quot;require&quot;: &quot;./cjs/utils/*&quot;,
    &quot;types&quot;: &quot;./utils.d.ts&quot;
  },
  &quot;./initializers&quot;: {
    &quot;import&quot;: &quot;./initializers/index.js&quot;,
    &quot;require&quot;: &quot;./cjs/initializers/index.js&quot;,
    &quot;types&quot;: &quot;./initializers.d.ts&quot;
  },
  &quot;./constants&quot;: {
    &quot;import&quot;: &quot;./constants/index.js&quot;,
    &quot;require&quot;: &quot;./cjs/constants/index.js&quot;,
    &quot;types&quot;: &quot;./constants.d.ts&quot;
  }
}

</code></pre>
<p>We export, for example, <code>./react-utils</code> and <code>./react-utils/*</code> because we want to
support both import styles below.</p>
<pre><code class="language-js">import { useLocalStorage } from &quot;neetocommons/react-utils&quot;;
</code></pre>
<pre><code class="language-js">import useLocalStorage from &quot;neetocommons/react-utils/useLocalStorage&quot;;
</code></pre>
<p>We initially employed the first import style, but as we expanded, we recognized
the necessity of supporting a more concise approach in smaller projects. This
second method involves importing solely the target file without additional
dependencies, significantly improving tree-shaking capabilities.</p>
<p>We also ensure we build for <code>esm</code> and <code>cjs</code>. Below is our simplified Babel
config.</p>
<pre><code class="language-js">const defaultConfigurations = require(&quot;./defaultConfigurations&quot;);

const alias = {
  assets: &quot;./src/assets&quot;,
  neetocist: &quot;@bigbinary/neeto-cist&quot;,
  // others
};

module.exports = function (api) {
  const config = defaultConfigurations(api);
  config.sourceMaps = true;

  config.plugins.push(
    [&quot;module-resolver&quot;, { root: [&quot;./src&quot;], alias }],
    &quot;inline-react-svg&quot;
  );

  if (process.env.BABEL_MODE === &quot;commonjs&quot;) {
    config.overrides = [
      {
        presets: [[&quot;@babel/preset-env&quot;, { modules: &quot;commonjs&quot; }]],
      },
    ];
  }
  return config;
};
</code></pre>
<p>When transpiling, we ensure aliases are correctly resolved, and if there are any
SVG files, we inline them using the
<a href="https://www.npmjs.com/package/babel-plugin-inline-react-svg"><code>inline-react-svg</code></a>
plugin to make life easy for the host application. Below is our build script.</p>
<pre><code class="language-json">&quot;scripts&quot;: {
  &quot;build:pre&quot;: &quot;del-cli dist&quot;,
  &quot;build:es&quot;: &quot;babel  --extensions \&quot;.js,.jsx\&quot; src --out-dir=dist&quot;,
  &quot;build:cjs&quot;: &quot;BABEL_MODE=commonjs babel  --extensions \&quot;.js,.jsx\&quot; src --out-dir=dist/cjs&quot;,
  &quot;build:post&quot;: &quot;node ./.scripts/post-build.mjs&quot;,
  &quot;build&quot;: &quot;yarn build:pre &amp;&amp; yarn build:es &amp;&amp; yarn build:cjs &amp;&amp; yarn build:post&quot;,
}
</code></pre>
<h2>Release</h2>
<p>We did not want to create a release every time we merged a PR, and we also
didn't want to manually release packages every time. Instead, we rely on GitHub
Labels while running Github Actions to do the release.</p>
<p>We created three labels specifically for this purpose: <code>patch</code>, <code>minor</code> and
<code>major</code>. As the names suggest, these labels help us create <code>patch</code>, <code>minor</code> and
<code>major</code> versions. When we create a PR and want to do a release when merging,
attach any of these labels, and GitHub Action will create releases accordingly.</p>
<pre><code class="language-yaml">name: &quot;Create and publish releases&quot;
on:
  pull_request:
    branches:
      - main
    types: [closed]
jobs:
  release:
    name: &quot;Create Release&quot;
    runs-on: ubuntu-latest
    if: &gt;-
      ${{ github.event.pull_request.merged == true &amp;&amp; (
      contains(github.event.pull_request.labels.*.name, 'patch') ||
      contains(github.event.pull_request.labels.*.name, 'minor') ||
      contains(github.event.pull_request.labels.*.name, 'major') ) }}
</code></pre>
<p>As evident from the code above, we trigger the <code>Create and publish releases</code>
GitHub Action only if any of the three aforementioned labels are present. Once
that condition is met, we proceed to use
<a href="https://classic.yarnpkg.com/lang/en/docs/cli/version/"><code>yarn version</code></a> to
update the version.</p>
<pre><code class="language-yaml">- name: Bump the patch version and create a git tag on release
  if: ${{ contains(github.event.pull_request.labels.*.name, 'patch') }}
  run: yarn version --patch --no-git-tag-version

- name: Bump the minor version and create a git tag on release
  if: ${{ contains(github.event.pull_request.labels.*.name, 'minor') }}
  run: yarn version --minor --no-git-tag-version

- name: Bump the major version and create a git tag on release
  if: ${{ contains(github.event.pull_request.labels.*.name, 'major') }}
  run: yarn version --major --no-git-tag-version
</code></pre>
<p>Then, we extract changelogs from PR's title and description.</p>
<pre><code class="language-yaml">- name: Extract changelog
  id: CHANGELOG
  run: |
    content=$(echo '${{ steps.PR.outputs.pr_body }}' | python3 -c 'import json; import sys; print(json.dumps(sys.stdin.read().partition(&quot;**Description**&quot;)[2].partition(&quot;**Checklist**&quot;)[0].strip()))')
    echo &quot;CHANGELOG=${content}&quot; &gt;&gt; $GITHUB_ENV
  shell: bash

- name: Update Changelog
  continue-on-error: true
  uses: stefanzweifel/changelog-updater-action@v1
  with:
    latest-version: ${{ steps.package-version.outputs.version }}
    release-notes: ${{ fromJson(env.CHANGELOG) }}
</code></pre>
<p>Finally, we publish the package to NPM.</p>
<pre><code class="language-yaml">- name: Publish the package on NPM
  uses: JS-DevTools/npm-publish
  with:
    access: &quot;public&quot;
    token: ${{ secrets.NPM_TOKEN }}
</code></pre>
<h2>Maintenance</h2>
<p>Now that the release is done, we need to propagate changes to our products. For
example, we may have extracted an existing functionality from one of the
packages. Here is an example of
<a href="https://www.bigbinary.com/blog/how-we-standardized-keyboard-shortcuts">how we standardized keyboard shortcuts in neeto</a>
and extracted out into a package. Now, the product team needs to remove that
functionality and use it from the package. Reaching out to each team and asking
them to replace it can be tedious, especially considering their priorities. So
we came up with a plan to use custom
<a href="https://eslint.org/docs/latest/extend/custom-rules">ESLint rules</a> to enforce
them, and we built <code>eslint-plugin-neeto</code>.</p>
<p>Let's look at a few examples of how we use <code>eslint-plugin-neeto</code> to enforce
changes on the product team.</p>
<p>There are some third-party packages we decided not to use when we found better
alternatives, and they even included our own. For example, <code>bootstrap</code>,
<code>moment.js</code>, <code>@bigbinary/neeto-utils</code>, etc. To enforce this, we create ESLint
rules called <code>no-blacklisted-imports</code>. This rule throws a lint error if
developers attempt to commit changes that include these blacklisted imports.</p>
<p>Another example is that we moved higher-level constants, commonly utilized
across various products, to <code>neeto-commons</code>. To enforce this, we created an
ESLint rule called <code>use-common-constants</code>. This rule detects any local imports
and recommends importing from <code>neeto-commons</code> instead.</p>
<p>Here is another great blog post in which we explained the challenges we faced
while
<a href="https://www.bigbinary.com/blog/react-localization">adding translations and enforcing them using ESLint and Babel plugins</a>.</p>
<p>These are just a few of the many ESLint and Babel plugins we created.</p>
]]></content>
    </entry>
  <entry>
      <title type="text"><![CDATA[dependencies vs devDependencies vs peerDependencies]]></title>
      <link rel="alternate" type="text/html" href="https://www.bigbinary.com/blog/different-dependencies"/>
      <link rel="enclosure" type="image/jpeg" href="https://www.bigbinary.com/blog/images/social_preview_images/dependencies_devdepencied_peerdependencies.jpg"/>
      <id>https://www.bigbinary.com/blog/different-dependencies</id>
      <published>2024-05-14T00:00:00.000Z</published>
      <updated>2024-05-14T00:00:00.000Z</updated>
      <author>
        <name>Farhan CK</name>
        <uri>https://www.bigbinary.com/blog/authors/farhanlatheef</uri>
      </author>
      <category term="ReactJS"/>
      <category term="npm"/>
      <media:thumbnail url="https://www.bigbinary.com/blog/images/social_preview_images/dependencies_devdepencied_peerdependencies.jpg" width="1200" height="627"/>
      <summary type="text"><![CDATA[Difference between dependencies, devDependencies and peerDependencies]]></summary>
      <content type="html" xml:base="https://www.bigbinary.com/blog/different-dependencies"><![CDATA[<p>In a JavaScript project, understanding the distinctions between <code>dependencies</code>,
<code>devDependencies</code>, and <code>peerDependencies</code> is crucial for effective package
management. Each plays a distinct role in shaping how a project is built and
distributed. In this blog, we'll explore these terms and their differences.</p>
<h2>dependencies</h2>
<p>The packages that are really needed for a project to function should be listed
under <code>dependencies</code>. These packages are always installed within that project.
If the project is also a package, then these dependencies will also get
installed in the host project that uses this package. Below are some common
examples of what might go under <code>dependencies</code>.</p>
<pre><code class="language-json"> &quot;dependencies&quot;: {
   &quot;dayjs&quot;: &quot;1.11.1&quot;,
   &quot;immer&quot;: &quot;^10.0.2&quot;,
   &quot;ramda&quot;: &quot;^0.29.0&quot;,
   &quot;react&quot;: &quot;^18.2.0&quot;
 }
</code></pre>
<p>It's important to understand that the above packages do not always have to be
under <code>dependencies</code>. For example, if <code>dayjs</code> is needed only for development,
deployment or testing purposes, It should not be listed under <code>dependencies</code> but
rather in the <code>devDependencies</code> section, because <code>dependencies</code> will be bundled
with the main code, whereas <code>devDependencies</code> will not. So adding dependencies
that are only used in development purposes under <code>dependencies</code> is unnecessary
and will increase the bundle size, affecting the performance of the application.</p>
<p>To add a package to <code>dependencies</code> section, simply run:</p>
<pre><code class="language-bash">yarn add package-name
</code></pre>
<p>If we are shipping a package, all our dependencies are installed in the root of
host projects <code>node_modules</code>. However, an exception occurs if the host project
already has the same dependency but with a different version. In this scenario,
that specific conflicting dependency will be installed within the <code>node_modules</code>
of our package to avoid version conflicts.</p>
<p>To explain it bit more lets say we have <code>dayjs@1.0.0</code> as one of our dependency
but the host project uses <code>2.0.0</code>. Then both versions will be installed, <code>2.0.0</code>
would be the in root <code>node_modules</code> and <code>1.0.0</code> in our package's <code>node_modules</code>.
This way, our package can continue to use <code>1.0.0</code> while the host uses <code>2.0.0</code>. The
folder structure of that host will look something like below.</p>
<pre><code class="language-javascript">host-project-app
├── src
│   └── index.js
├── node_modules
│   └── react
│   └── dayjs
│   └── my-awesome-lib
│     └── node_modules
│       └── dayjs
├── package.json
└── README.md
</code></pre>
<h2>devDependencies</h2>
<p>Packages listed in <code>devDependencies</code> are used specifically for development
purposes. Any dependencies that do not go into our actual code are listed here
and not under <code>dependencies</code>. These dependencies won't be installed in a
production environment or in a host project if our project acts as a package.
Here are a few examples of what might belong in <code>devDependencies</code>.</p>
<pre><code class="language-json"> &quot;devDependencies&quot;: {
    &quot;@babel/core&quot;: &quot;^7.16.5&quot;,
    &quot;eslint&quot;: &quot;^8.41.0&quot;,
    &quot;husky&quot;: &quot;^7.0.4&quot;,
    &quot;jest&quot;: &quot;27.5.1&quot;,
    &quot;prettier&quot;: &quot;^2.8.8&quot;
 }
</code></pre>
<p>Just like in <code>dependencies</code>, these packages may not always be in
<code>devDependencies</code>. For example, if we are building a package that enhances Jest
tests capabilities, then we should place <code>jest</code> under <code>dependencies</code>. Otherwise
our host project will break, because <code>jest</code> will not be installed in the host
project.</p>
<p>To add a package to <code>devDependencies</code> section, simply run:</p>
<pre><code class="language-bash">yarn add -D package-name
</code></pre>
<h2>peerDependencies</h2>
<p><code>peerDependencies</code> are needed only if we are building a package. It allows host
to install any desired version unless we specify otherwise.</p>
<p>If we are using <code>yarn</code> as the package manager then <code>peerDependencies</code> are not
installed automatically. We have to install manually, even in our own package.
But there is a slight difference if you are using <code>npm</code>. Up to version 6 <code>npm</code>
does not install <code>peerDependencies</code> automatically. However, this changes from
version 7 onwards, as it will install <code>peerDependencies</code> automatically. So if we
are using <code>yarn</code> or <code>npm&lt;=v6</code> and we have for example Storybook or Jest tests in
our package project, then we have to install <code>peerDependencies</code> as
<code>devDependencies</code>(not as <code>dependencies</code> which defeats the purpose) as well.</p>
<pre><code class="language-json"> &quot;devDependencies&quot;: {
    &quot;@babel/core&quot;: &quot;^7.16.5&quot;,
    &quot;eslint&quot;: &quot;^8.41.0&quot;,
    &quot;husky&quot;: &quot;^7.0.4&quot;,
    &quot;jest&quot;: &quot;27.5.1&quot;,
    &quot;prettier&quot;: &quot;^2.8.8&quot;,
    &quot;dayjs&quot;: &quot;1.11.1&quot;,
 }
 &quot;peerDependencies&quot;: {
    &quot;dayjs&quot;: &quot;latest&quot;
 }
</code></pre>
<p>You might wonder about its purpose if manual installation is required. It serves
as a means for our package project to specify essential dependencies required
for the package to function properly. Simultaneously, it grants control to the
host project to choose which versions to install.</p>
<p>To add a package to <code>peerDependencies</code> section, simply run:</p>
<pre><code class="language-bash">yarn add --peer package-name
</code></pre>
<p>Now the tricky part is determining whether a particular dependency should go
under <code>dependencies</code> or <code>peerDependencies</code>. Unfortunately, there is no clear
answer here. But there are some questions we can ask ourselves to narrow it down.</p>
<ol>
<li>
<p>If the specific version of the dependency is important for our package, that
is if using a different version breaks our package, then definitely we want
to place that package under <code>dependencies</code>.</p>
<p>It is possible to place such dependencies under <code>peerDependencies</code> and
specify supported versions like below, but it is not a good practice.</p>
</li>
</ol>
<pre><code class="language-json"> &quot;peerDependencies&quot;: {
    &quot;dayjs&quot;: &quot;1.2.0 || 1.5.1&quot;,
 }
</code></pre>
<ol start="2">
<li>If the dependency is a widely used package like <code>react</code>, better place it
under <code>peerDependency</code>and ensure that our package works with different
version of that dependency. This way, the dependency installed in the host
project can be reused by our package without installing a separate version.</li>
<li>If we want to make changes to a dependency in a manner that impacts its usage
within the host project, then place it under <code>peerDependencies</code>. Good example
of this is, at <a href="https://www.neeto.com/">neeto</a> we have a package called
<code>neeto-commons-frontend</code> which extracts numerous common functionalities
utilized across various products. One such functionality is our error
handling system, for which we use an
<a href="https://axios-http.com/docs/interceptors">Axios interceptor</a>. To ensure the
functionality of this interceptor, it's crucial to apply this interceptor to
the same instance of Axios. To elaborate further, if we add Axios under
<code>dependencies</code> in <code>neeto-commons-frontend</code>, but the host project uses a
different Axios version, we will be making changes to the Axios instance
that's in <code>node_modules</code> of <code>neeto-commons-frontend</code> and not of the host
project, means the functionality will not work on the host project.</li>
</ol>
<p>Another rationale behind utilizing <code>peerDependencies</code> is its substantial impact
on reducing the bundle size, particularly when bundling our package. Now if we
are using Rollup, placing certain packages under <code>peerDependencies</code> doesn't
automatically exclude them from the bundle. We need to explicitly specify this
in the Rollup configuration. This is achieved through the Rollup <code>external</code>
configuration option, where we provide a list of <code>peerDependencies</code> to be
excluded from the bundle. To simplify this process,
<code>rollup-plugin-peer-deps-external</code> automates the inclusion of <code>peerDependencies</code>
within the <code>external</code> configuration.</p>
<pre><code class="language-js">import peerDepsExternal from &quot;rollup-plugin-peer-deps-external&quot;;

export default {
  plugins: [
    // Preferably set as first plugin.
    peerDepsExternal(),
  ],
};
</code></pre>
]]></content>
    </entry>
</feed>