<?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: Travis Swavely</title>
    <description>The latest articles on DEV Community by Travis Swavely (@brohvis).</description>
    <link>https://dev.to/brohvis</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%2F1507119%2Fbcd1b47a-5e00-4402-846b-fa6a5b923be3.png</url>
      <title>DEV Community: Travis Swavely</title>
      <link>https://dev.to/brohvis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brohvis"/>
    <language>en</language>
    <item>
      <title>Uncomplicating SVG in Next.js</title>
      <dc:creator>Travis Swavely</dc:creator>
      <pubDate>Mon, 20 May 2024 18:47:01 +0000</pubDate>
      <link>https://dev.to/brohvis/uncomplicating-svg-in-nextjs-4j3l</link>
      <guid>https://dev.to/brohvis/uncomplicating-svg-in-nextjs-4j3l</guid>
      <description>&lt;p&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%2Fuploads%2Farticles%2F8m2i3qo7jr7nf5n02scb.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%2Fuploads%2Farticles%2F8m2i3qo7jr7nf5n02scb.png" alt="svgmagic.org Screenshot" width="800" height="645"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Simplify Your SVG Workflow with svgMagic
&lt;/h2&gt;

&lt;p&gt;SVGs are a vital part of modern web development, offering scalability and crisp visuals. However, integrating and managing them can sometimes be challenging. That's where svgMagic comes in, providing an efficient solution for incorporating SVGs into your Next.js projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is svgMagic?
&lt;/h2&gt;

&lt;p&gt;svgMagic is a powerful tool that streamlines SVG and simplifies the process of adding, replacing and styling SVGs. With the power of Next.js, TailwindCSS, and MDX, we can create phenomenal stylized vector graphics anywhere in our app easily.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Easy Installation&lt;/strong&gt;: Get started quickly with npm, Yarn, or PNPM.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pre-built Components&lt;/strong&gt;: Use pre-loaded SVGs or import your own.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Styling Options&lt;/strong&gt;: Customize SVGs with Vanilla CSS or Tailwind CSS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Management&lt;/strong&gt;: Handle SVGs dynamically within your projects.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Getting Started with svgMagic
&lt;/h2&gt;

&lt;p&gt;Let's walk through the steps to integrate svgMagic into a Next.js project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;First, install svgMagic using your preferred package manager:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i svgmagic
&lt;span class="c"&gt;# or&lt;/span&gt;
yarn add svgmagic
&lt;span class="c"&gt;# or&lt;/span&gt;
pnpm i svgmagic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Prerequisite Configurations
&lt;/h3&gt;

&lt;p&gt;This should add SVGR as a peer dependency and install it if it isn't already, but, just in case - you can check your package.json or install it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i @svgr/webpack
&lt;span class="c"&gt;# or&lt;/span&gt;
yarn add @svgr/webpack
&lt;span class="c"&gt;# or&lt;/span&gt;
pnpm i @svgr/webpack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, ensure SVGR is your loader in your &lt;code&gt;next.config.js&lt;/code&gt; file.&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="nf"&gt;webpack&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;config&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;rules&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&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="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;svg$/&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="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@svgr/webpack&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;return&lt;/span&gt; &lt;span class="nx"&gt;config&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;h3&gt;
  
  
  Setup Script
&lt;/h3&gt;

&lt;p&gt;Lastly, run the &lt;code&gt;svgm-setup&lt;/code&gt; script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;svgm-setup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And choose whether to scaffold the example &lt;code&gt;.svg&lt;/code&gt; files, and change the directory if you want to. &lt;/p&gt;

&lt;p&gt;All of the &lt;code&gt;.svg&lt;/code&gt; files in the subdirectory containing the scaffolded &lt;code&gt;SVGM.tsx&lt;/code&gt; component will be automatically loaded going forward by their file name.&lt;/p&gt;

&lt;p&gt;For deeper installation instructions, styled live examples, and detailed documentation, visit the &lt;a href="https://svgmagic.org" rel="noopener noreferrer"&gt;svgMagic&lt;/a&gt; home page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using svgMagic in a Parent Component
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;SVGM&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;@/components/svgm/SVGM&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ExampleComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&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="nc"&gt;SVGM&lt;/span&gt; &lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"svgm-mark"&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"h-8 w-8 text-white"&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;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;ExampleComponent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to use it in MDX and pass the props right there, it works great, just ensure it gets imported with your &lt;code&gt;mdx-components&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Customizing SVGs with Tailwind CSS
&lt;/h3&gt;

&lt;p&gt;svgMagic supports Tailwind CSS, allowing you to easily style your SVGs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SVGM&lt;/span&gt; &lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"example-icon"&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"w-6 h-6 text-blue-500"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code applies width, height, and color classes from Tailwind CSS to the SVG.&lt;/p&gt;

&lt;p&gt;This means we can target things like dark mode with &lt;code&gt;dark:&lt;/code&gt;, too. For more examples, visit &lt;a href="https://svgmagic.org" rel="noopener noreferrer"&gt;https://svgmagic.org&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;svgMagic is an excellent, &lt;em&gt;free&lt;/em&gt;, and &lt;strong&gt;open source&lt;/strong&gt; tool for managing SVGs in your web projects, offering easy integration, customization, and dynamic handling. Whether you're building with Next.js or another framework, svgMagic can simplify your SVG workflow.&lt;/p&gt;

&lt;p&gt;Explore more about svgMagic and start integrating it into your projects today!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/brohvis/svgmagic" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Star on GitHub&lt;/a&gt;
&lt;/p&gt;




&lt;h3&gt;
  
  
  Relevant Links
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://svgmagic.org/docs" rel="noopener noreferrer"&gt;Homepage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://svgmagic.org/docs" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/brohvis/svgmagic" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/svgmagic" rel="noopener noreferrer"&gt;npm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.producthunt.com/posts/svgmagic" rel="noopener noreferrer"&gt;Product Hunt&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/sponsors/brohvis" rel="noopener noreferrer"&gt;Sponsor svgMagic&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>tutorial</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
