<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>gulp | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/tag/gulp/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Fri, 23 Jul 2021 15:06:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Migrating from gulp to esbuild</title>
		<link>https://nerdpress.org/2021/07/23/migrating-from-gulp-to-esbuild/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Fri, 23 Jul 2021 15:06:46 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[esbuild]]></category>
		<category><![CDATA[gulp]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[sass]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3066</guid>

					<description><![CDATA[<p>Esbuild is the new cool kid in the bundler world.It is super fast since its written in Go and comes with a lot of builtin features for modern frontend development. So i wanted to try it myself and migrated a former gulp build to esbuild. But as it showed the gulp build was not so &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2021/07/23/migrating-from-gulp-to-esbuild/" class="more-link">Continue reading<span class="screen-reader-text"> "Migrating from gulp to esbuild"</span></a></p>
The post <a href="https://nerdpress.org/2021/07/23/migrating-from-gulp-to-esbuild/">Migrating from gulp to esbuild</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p><a href="https://esbuild.github.io/" target="_blank" rel="noreferrer noopener">Esbuild</a> is the new cool kid in the bundler world.<br />It is super fast since its written in Go and comes with a lot of builtin features for modern frontend development.</p>



<p>So i wanted to try it myself and migrated a former <a href="https://gulpjs.com/" title="https://gulpjs.com/" target="_blank" rel="noreferrer noopener">gulp</a> build to esbuild.</p>



<p>But as it showed the gulp build was not so modern, as it was just Sass and Javascript minification. No ES6, No React, no JSX with inline styles.</p>



<p>So Esbuild was not working out of the box but needed some extra config and the <a href="https://www.npmjs.com/package/esbuild-plugin-sass" target="_blank" rel="noreferrer noopener">Sass plugin</a>.</p>



<p><code>npm i -d esbuild esbuild-plugin-sass</code></p>



<p>Also I had to rewrite the Javascript to use ES6 modules, but this was fortunatly easy.</p>



<span id="more-3066"></span>



<p>When using a plugin we need to create our own build file and configure esbuild to use the Sass plugin.<br />esbuild.js:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
const esbuild = require(&#039;esbuild&#039;);
const sassPlugin = require(&#039;esbuild-plugin-sass&#039;);

esbuild.build({
  entryPoints: &#x5B;&quot;main.js&quot;],
  bundle: true,
  minify: true,
  format: &#039;iife&#039;,
  platform: &#039;browser&#039;,
  outfile:&quot;main.min.js&quot;,
  plugins: &#x5B;sassPlugin()]
}).catch((err) =&gt; {
  console.log(err)
})
</pre></div>


<p>Ok, but where are the Sass files now?<br />With ES6 you can import styles and then esbuild &amp; the sassPlugin can follow this path from the entrypoint file and create the CSS file from the source Sass file.</p>



<p>So in main.js import the styles:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
import $ from &#039;jquery&#039;
import &#039;./style.scss&#039;
...
</pre></div>


<p>Now you can call the esbuild.js file:</p>



<p><code>node ./esbuild.js</code></p>



<p><em>(Yeah no file watchers here, just manual trigger ;))</em></p>



<p>This will bundle the javascript to main.min.js and also create a main.min.css file.</p>



<p>Then include this in your HTML</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;link rel=&quot;stylesheet&quot; href=&quot;/main.min.css&quot;&gt; 
&lt;script src=&quot;/main.min.js&quot;&gt;&lt;/script&gt;
</pre></div>


<p>and you are done. :)</p>The post <a href="https://nerdpress.org/2021/07/23/migrating-from-gulp-to-esbuild/">Migrating from gulp to esbuild</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
