diff options
Diffstat (limited to 'vendor/fguillot/picofeed/tests/fixtures/lincoln_loop.xml')
-rw-r--r-- | vendor/fguillot/picofeed/tests/fixtures/lincoln_loop.xml | 1150 |
1 files changed, 0 insertions, 1150 deletions
diff --git a/vendor/fguillot/picofeed/tests/fixtures/lincoln_loop.xml b/vendor/fguillot/picofeed/tests/fixtures/lincoln_loop.xml deleted file mode 100644 index 8e18601c2..000000000 --- a/vendor/fguillot/picofeed/tests/fixtures/lincoln_loop.xml +++ /dev/null @@ -1,1150 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Lincoln Loop Blog</title><link>http://lincolnloop.com/blog/</link><description>Lincoln Loop Blog</description><atom:link href="http://lincolnloop.com/blog/feeds/latest/" rel="self"></atom:link><language>en-us</language><lastBuildDate>Tue, 13 May 2014 11:51:13 -0500</lastBuildDate><item><title>High Performance Django Kickstarter Project</title><link>http://lincolnloop.com/blog/high-performance-django-kickstarter-project/</link><description> -<p><strong>Please update to our new feed url: <a href="http://lincolnloop.com/blog/feed/">lincolnloop.com/blog/feed/</a></strong></p> -<hr/> -<p><a href="https://www.kickstarter.com/projects/1704706557/high-performance-django" style="float:left;display:inline-block; margin: 0 2em 1em 0"><img src="http://lincolnloop.com/uploads/uploads/hpd_cover.jpg" alt=""></a></p>
-
-<p>I&#39;m really excited to (finally) announce that we are writing a book! We&#39;ve been working with Django professionally for a long time (over 7 years now). During that time, we&#39;ve learned <em>a lot</em> about how to use the framework to build fast and scalable websites. We&#39;re bundling up all that knowledge into an e-book called <strong><em>High Performance Django</em></strong> and it is up on <a href="https://www.kickstarter.com/projects/1704706557/high-performance-django">Kickstarter</a> today.</p>
-
-<p>We&#39;re already well into the writing process, so we can tell you a little about what you&#39;ll get. The book is heavy on Django tips, but also reaches far beyond Python, showing you how to architect and tune the rest of your stack. It gives you an opinionated battle-tested blueprint utilizing many of the same techniques as high-profile Django sites like Disqus, Instagram, and Pintrest.</p>
-
-<p>We hope to get the first edition out in July, but we need your help to make that happen. Writing and editing the book is going to be a massive undertaking and you can help support our effort. <a href="https://www.kickstarter.com/projects/1704706557/high-performance-django">Give us your vote of confidence by backing the project today</a>!</p></description><pubDate>Tue, 13 May 2014 11:51:13 -0500</pubDate><guid>http://lincolnloop.com/blog/high-performance-django-kickstarter-project/</guid></item><item><title>A Look at CSS Rule Organization</title><link>http://lincolnloop.com/blog/look-css-rule-organization/</link><description> -<p><strong>Please update to our new feed url: <a href="http://lincolnloop.com/blog/feed/">lincolnloop.com/blog/feed/</a></strong></p> -<hr/> -<p>CSS preprocessors have given us a handful of tools to re-architect our front-end code. We can keep things DRY with includes and extends or perhaps use nesting for code organization. All of these features allow a CSS rule to grow in complexity, but few people ever talk about managing that problem.</p> - -<p>Let&#39;s take a look at a modern CSS rule. We&#39;ll talk about how they&#39;re structured and why we do what we do. Perhaps this will help you organize your own CSS!</p> - -<p>Here&#39;s a very standard box. It is one of many box styles in our pretend design. It&#39;s sole purpose is to feature and highlight content and it can live almost anywhere in our UI.</p> - -<p>(Note, we use SCSS primarily so all our demo code will as well.)</p> - -<pre class="highlight"><code data-syntax="scss"><span class="nc">.featured-box</span> <span class="p">{</span> - <span class="k">@extend</span> <span class="err">%</span><span class="nt">center-box</span><span class="o">;</span> <span class="o">//</span> <span class="nt">Placeholder</span> <span class="nt">selectors</span> <span class="nt">first</span> - <span class="o">@</span><span class="nt">extend</span> <span class="nc">.info-box</span><span class="o">;</span> <span class="o">//</span> <span class="nt">Modifier</span> <span class="nt">classes</span> <span class="nt">second</span> - - <span class="o">//</span> <span class="nt">All</span> <span class="nt">of</span> <span class="nt">the</span> <span class="nt">regular</span> <span class="nt">properties</span><span class="nc">.</span> - <span class="o">//</span> <span class="nt">Remember</span> <span class="nt">your</span> <span class="nt">grouping</span><span class="o">!</span> - <span class="nt">width</span><span class="nd">:</span> <span class="nt">90</span><span class="err">%</span><span class="o">;</span> - <span class="nt">height</span><span class="nd">:</span> <span class="nt">100px</span><span class="o">;</span> - - <span class="nt">background</span><span class="nd">:</span> <span class="nt">blue</span><span class="o">;</span> - - <span class="o">@</span><span class="nt">include</span> <span class="nt">fadeIn</span><span class="o">(</span><span class="nt">1</span><span class="nc">.5s</span><span class="o">);</span> - - <span class="o">//</span> <span class="nt">Sub-selectors</span> <span class="nt">specific</span> <span class="nt">to</span> <span class="nt">this</span> <span class="nt">selector</span> - <span class="o">//</span> <span class="nt">Compiles</span> <span class="nt">to</span> <span class="nc">.featured-box</span> <span class="nc">.title</span> - <span class="k">&</span> <span class="o">&gt;</span> <span class="nc">.title</span> <span class="p">{</span> - <span class="na">font-weight</span><span class="o">:</span> <span class="no">bold</span><span class="p">;</span> - <span class="p">}</span> - - <span class="c1">// Handle state. e.g. active, inactive, selected, etc.</span> - <span class="c1">// Compiles to .featured-box.is-active</span> - <span class="k">&</span><span class="nc">.is-active</span> <span class="p">{</span> - <span class="na">border</span><span class="o">:</span> <span class="mi">2</span><span class="kt">px</span> <span class="no">solid</span> <span class="no">dotted</span><span class="p">;</span> - <span class="p">}</span> - - <span class="c1">// Any actions. Mostly standard interactivity</span> - <span class="c1">// Compiles to .featured-box:hover</span> - <span class="k">&</span><span class="nd">:hover</span> <span class="p">{</span> - <span class="na">background</span><span class="o">:</span> <span class="nb">green</span><span class="p">;</span> - <span class="p">}</span> - - <span class="c1">// Context specific styles</span> - <span class="c1">// Compiles to .sidebar .featured-box</span> - <span class="nc">.sidebar</span> <span class="k">&</span> <span class="p">{</span> - <span class="na">width</span><span class="o">:</span> <span class="mi">100</span><span class="kt">%</span><span class="p">;</span> - <span class="na">height</span><span class="o">:</span> <span class="no">auto</span><span class="p">;</span> - <span class="na">background</span><span class="o">:</span> <span class="ni">whitesmoke</span><span class="p">;</span> - <span class="p">}</span> - - <span class="c1">// Lastly, media queries!</span> - <span class="k">@media</span> <span class="o">(</span><span class="nt">min-width</span><span class="nd">:</span> <span class="nt">600px</span><span class="o">)</span> <span class="p">{</span> - <span class="na">width</span><span class="o">:</span> <span class="mi">50</span><span class="kt">%</span><span class="p">;</span> - <span class="na">margin</span><span class="o">:</span> <span class="mi">0</span> <span class="no">auto</span><span class="p">;</span> - <span class="p">}</span> -<span class="p">}</span></code></pre> - -<p>It helps to think that rules tell a story. Our rule has a name. It has &quot;parents&quot; via @extend. It has a few properties and when you interact with it, it will do something (change its background color to green). When put in different situations via media queries or in <code data-syntax="text-only">.sidebar</code>, it will change its appearance.</p> - -<p>Let&#39;s step through some of the best practices we use to build <code data-syntax="text-only">.featured-box</code>.</p> - -<h2>Extends First</h2> - -<pre class="highlight"><code data-syntax="scss"><span class="nc">.featured-box</span> <span class="p">{</span> - <span class="k">@extend</span> <span class="err">%</span><span class="nt">center-box</span><span class="o">;</span> <span class="o">//</span> <span class="nt">Placeholder</span> <span class="nt">selectors</span> <span class="nt">first</span> - <span class="o">@</span><span class="nt">extend</span> <span class="nc">.info-box</span><span class="o">;</span> <span class="o">//</span> <span class="nt">Modifier</span> <span class="nt">classes</span> <span class="nt">second</span> - <span class="nc">...</span></code></pre> - -<p>Similar to includes, imports, or inheritance in other languages, we handle dependencies <em>first</em> by putting every @extend at the top. This cuts down on debug time later as we always know where to look for dependency problems.</p> - -<p><code data-syntax="text-only">%center-box</code> is a <a href="http://sass-lang.com/documentation/file.SASS_REFERENCE.html#placeholder_selectors_">placeholder selector</a>, which means its name does not get compiled in our output CSS. Instead, its properties appear wherever we call them.</p> - -<p>If you want to learn more about placeholder selectors, there are several <a href="http://www.sitepoint.com/sass-mixin-placeholder/">good articles</a> <a href="http://css-tricks.com/the-extend-concept/">on the topic</a>.</p> - -<p>@extend can be a tricky feature, as it can tinker with the ordering of our output CSS. All the more reason to put them early in our rule. Every bit of organization helps!</p> - -<p>Utility or modifier classes like <code data-syntax="text-only">.info-box</code> come next for similar reasons. I&#39;ll talk more about these in a moment.</p> - -<p>Another advantage to putting external dependencies first is that it clarifies what the final output will be for a rule, as anything in a dependency would be overridden.</p> - -<h2>Modifier Classes</h2> - -<p>It&#39;s not uncommon to have a base class with a few other classes that change the meaning of an element. You&#39;ll see this a lot with buttons or boxes, especially in frameworks:</p> - -<pre class="highlight"><code data-syntax="html"><span class="nt">&lt;section</span> <span class="na">class=</span><span class="s">&quot;box partner-content hidden-phone featured-box no-borders&quot;</span><span class="nt">&gt;&lt;/section&gt;</span></code></pre> - -<p>In this example, <code data-syntax="text-only">.box</code> is a base class that gives us some starting structure. We then inherit other styles through a series of modifier classes in an effort to nudge our box into place. This gets messy over time as we end up using a growing number of modifier classes to define what is essentially an unique element. This is where extends help again:</p> - -<pre class="highlight"><code data-syntax="scss"><span class="nc">.featured-partner</span> <span class="p">{</span> - <span class="k">@extend</span> <span class="nc">.partner-content</span><span class="o">;</span> - <span class="o">@</span><span class="nt">extend</span> <span class="nc">.featured-box</span><span class="o">;</span> - <span class="o">@</span><span class="nt">extend</span> <span class="nc">.no-borders</span><span class="o">;</span> - <span class="o">@</span><span class="nt">extend</span> <span class="nc">.hidden-phone</span><span class="o">;</span> -<span class="p">}</span></code></pre> - -<p>We can then use this to new rule to write a more semantic class attribute:</p> - -<pre class="highlight"><code data-syntax="html"><span class="nt">&lt;section</span> <span class="na">class=</span><span class="s">&quot;**box featured-partner**&quot;</span><span class="nt">&gt;&lt;/section&gt;</span></code></pre> - -<p>To get this effect without a CSS pre-processor we&#39;d have to write really long rules. This quickly becomes difficult to manage:</p> - -<pre class="highlight"><code data-syntax="css"><span class="nc">.featured-box</span><span class="o">,</span> -<span class="nc">.info-box</span><span class="o">,</span> -<span class="nc">.help-box</span><span class="o">,</span> -<span class="nc">.notification-box</span><span class="o">,</span> -<span class="nc">.user-info-box</span> <span class="p">{</span> - <span class="k">padding</span><span class="o">:</span> <span class="m">10px</span><span class="p">;</span> - <span class="k">font-size</span><span class="o">:</span> <span class="m">20px</span><span class="p">;</span> -<span class="p">}</span></code></pre> - -<p>It&#39;s important to note that using extends or includes creates a dependency, so be careful! Also, as a rule of thumb, you should try to stick to one base class, one modifier, and one state:</p> - -<pre class="highlight"><code data-syntax="scss"><span class="o">&lt;</span><span class="nt">section</span> <span class="nt">class</span><span class="o">=</span><span class="s2">&quot;**box featured-box is-selected**&quot;</span><span class="o">&gt;</span> <span class="o">&lt;/</span><span class="nt">section</span><span class="o">&gt;</span></code></pre> - -<p>That&#39;s much cleaner!</p> - -<h2>Basic Properties</h2> - -<p>Everyone seems to have a preferred order for properties. Some prefer alphabetical. Those who prefer grouping can almost never decide on the correct order. For example, I&#39;m a huge fan of defining components starting with the outside first, then working inward: </p> - -<ol> -<li>Where is the box? (position, z-index, margins/padding)</li> -<li>What kind of a box is it? (display, box-sizing)</li> -<li>How big is the box? (width, height)</li> -<li>Box shadows, borders, etc</li> -<li>Backgrounds</li> -<li>Typography</li> -</ol> - -<p>Intelligent grouping of properties will do a lot to ensure your CSS is accessible to other developers. Another common standard is &quot;one rule per line.&quot; As always, the most important guideline is <strong>be consistent</strong>.</p> - -<h2>Mixins</h2> - -<p>Here&#39;s where things get a little weird! You&#39;ll notice that we include a mixin in our rule:</p> - -<pre class="highlight"><code data-syntax="scss"><span class="k">@include</span><span class="nd"> fadeIn</span><span class="p">(</span><span class="mi">1</span><span class="mf">.5</span><span class="kt">s</span><span class="p">);</span></code></pre> - -<p>Technically, <code data-syntax="text-only">fadeIn()</code> is a dependency. So why isn&#39;t it at the top? Mixins perform operations and inject the resulting CSS into the rule. This means that they are often dependent upon property ordering defined within the same rule. Grouping them near related properties helps make sense of output CSS. In simpler cases, I recommend putting mixins right after basic properties but before sub-selectors, which we&#39;ll discuss next.</p> - -<h2>Sub-Selectors (or &quot;Think of the Children&quot;)</h2> - -<p>The next section of <code data-syntax="text-only">.featured-box</code> deals with specific styles for its children. In our example above we&#39;re targeting the <code data-syntax="text-only">.title</code> class specifically:</p> - -<pre class="highlight"><code data-syntax="scss"><span class="c1">// Sub-selectors specific to this selector</span> -<span class="c1">// Compiles to .featured-box .title</span> -<span class="k">&</span> <span class="o">&gt;</span> <span class="nc">.title</span> <span class="p">{</span> - <span class="na">font-weight</span><span class="o">:</span> <span class="no">bold</span><span class="p">;</span> -<span class="p">}</span></code></pre> - -<p>Notice that I didn&#39;t use a H3 or any other headline for that matter. Doing so restricts <code data-syntax="text-only">.featured-box</code> to a specific HTML structure, which may not always be best for accessibility or accurate with regard to the hierarchy of content. For example, <code data-syntax="text-only">.featured-box</code> could be used in a sidebar with a H4, or at the top of the page with a big H2.</p> - -<p>Complex objects could call for dozens of sub-selectors. When this happens, consider putting common styles in a base rule, and meatier objects (that may exist on their own) into their own rules. Expanding on our original example, let&#39;s pretend we have a stylized list within <code data-syntax="text-only">.featured-box</code>.</p> - -<pre class="highlight"><code data-syntax="scss"><span class="nc">.featured-box</span> <span class="p">{</span> - <span class="c1">// Lots of styles for </span> - <span class="nc">.tab-list</span> <span class="p">{</span> - <span class="c1">// 50 lines of styles for tabs!</span> - <span class="p">}</span> -<span class="p">}</span></code></pre> - -<p>This is less ideal than:</p> - -<pre class="highlight"><code data-syntax="scss"><span class="nc">.featured-box</span> <span class="p">{</span> - <span class="c1">// Everything in our original example</span> -<span class="p">}</span> - -<span class="nc">.featured-box</span> <span class="nc">.tab-list</span> <span class="p">{</span> - <span class="c1">// 50 lines of styles for tabs!</span> -<span class="p">}</span></code></pre> - -<p>In this way we aren&#39;t losing the <em>special case</em> that is a <code data-syntax="text-only">.tab-list</code> inside of a <code data-syntax="text-only">.featured-box</code> amongst all the other styles.</p> - -<h2>State and Actions</h2> - -<p>CSS gives us a few actions to work with specific to our selected element. Most elements have :focus or :hover. Anchors have :visited and radio buttons have :checked. Often we shim these with classes or data attributes for use in richer interfaces:</p> - -<pre class="highlight"><code data-syntax="html"><span class="nt">&lt;button</span> <span class="na">type=</span><span class="s">&quot;submit&quot;</span> <span class="na">class=</span><span class="s">&quot;btn **is-sending**&quot;</span><span class="nt">&gt;</span>Sending...<span class="nt">&lt;/button&gt;</span></code></pre> - -<p>Actions and state are usually dependent upon basic properties, but are often overridden depending on context. For example, the animation we may associate with <code data-syntax="text-only">.is-sending</code> may be different on desktop than on mobile, or we may have to override a color on hover of an anchor&#39;s default :link state.</p> - -<p>As a side note, notice that I am using <code data-syntax="text-only">.is-sending</code> instead of <code data-syntax="text-only">.sending</code>. I always append <code data-syntax="text-only">.is-</code> to state classes to more clearly convey what they are.</p> - -<h2>Context Specific Styles</h2> - -<p>Context related styles always come last because they often have radical changes to appearance and layout. This fits well with a mobile first strategy, as you can clearly denote the <em>evolution</em> of a rule as you gain screen space.</p> - -<p>In our example above, we&#39;re noting two different context changes:</p> - -<ol> -<li>When <code data-syntax="text-only">.featured-box</code> is in <code data-syntax="text-only">.sidebar</code>.</li> -<li>When <code data-syntax="text-only">.featured-box</code> is on a larger display.</li> -</ol> - -<pre class="highlight"><code data-syntax="scss"><span class="c1">// Context specific styles</span> -<span class="c1">// Compiles to .sidebar .featured-box</span> -<span class="nc">.sidebar</span> <span class="k">&</span> <span class="p">{</span> - <span class="na">width</span><span class="o">:</span> <span class="mi">100</span><span class="kt">%</span><span class="p">;</span> - <span class="na">height</span><span class="o">:</span> <span class="no">auto</span><span class="p">;</span> - <span class="na">background</span><span class="o">:</span> <span class="ni">whitesmoke</span><span class="p">;</span> -<span class="p">}</span> - -<span class="c1">// Lastly, media queries!</span> -<span class="k">@media</span> <span class="o">(</span><span class="nt">min-width</span><span class="nd">:</span> <span class="nt">600px</span><span class="o">)</span> <span class="p">{</span> - <span class="na">width</span><span class="o">:</span> <span class="mi">50</span><span class="kt">%</span><span class="p">;</span> - <span class="na">margin</span><span class="o">:</span> <span class="mi">0</span> <span class="no">auto</span><span class="p">;</span> -<span class="p">}</span></code></pre> - -<p>In this scenario, we want <code data-syntax="text-only">.featured-box</code> to be full width and have a subtle appearance when in <code data-syntax="text-only">.sidebar</code>. On larger screens, we want it to be 50% of the available width and ensure that no matter what it is center aligned regardless of other styles. The ordering doesn&#39;t matter here due to the specificity of the two changes. <code data-syntax="text-only">.sidebar &</code> will trump the media query change.</p> - -<p>However, we put media queries last in rules because they most often deal with layout related changes, and putting those sort of changes in a predictable place in the same way we handled extends helps with debugging.</p> - -<p><a href="http://filamentgroup.com/lab/element_query_workarounds/">Per element media queries</a> could alleviate some of the pain here, but at the time of this writing we do not have a clean CSS-only solution. Though <a href="https://github.com/Snugug/eq.js">many people</a> have put together <a href="http://www.smashingmagazine.com/2013/06/25/media-queries-are-not-the-answer-element-query-polyfill/">workable solutions</a>. Things can get out of hand when you have to consider an element&#39;s appearance not only across browsers and devices, but location in the UI and relation to other elements. </p> - -<h2>That&#39;s It!</h2> - -<p>This just scratches the surface of what it takes to write clean, maintainable CSS architecture. In the wild, our <code data-syntax="text-only">.featured-box</code> rule would likely be more complicated, with more dependencies, basic properties, and context changes. What best practices does your team follow to help keep complexity at bay?</p> -</description><pubDate>Thu, 08 May 2014 12:11:41 -0500</pubDate><guid>http://lincolnloop.com/blog/look-css-rule-organization/</guid></item><item><title>Speedy Browserifying with Multiple Bundles</title><link>http://lincolnloop.com/blog/speedy-browserifying-multiple-bundles/</link><description> -<p><strong>Please update to our new feed url: <a href="http://lincolnloop.com/blog/feed/">lincolnloop.com/blog/feed/</a></strong></p> -<hr/> -<p>Last month I talked about one of my favorite tools for JavaScript on the front end, <a href="http://lincolnloop.com/blog/untangle-your-javascript-browserify/">Browserify</a>, which allows you to create modular code for the browser using CommonJS modules and npm. It does this by combining the dependencies into an all-in-one bundle. In development, typically you will watch your JavaScript files for changes and then recompile the bundle.</p> - -<p>If you&#39;re including some large dependencies in your bundle, though, you may have noticed that it can take several seconds to regenerate that bundle each time you edit a module. This usually isn&#39;t a big problem, but when you want to rapidly hack on a UI feature and frequently refresh to see your changes this several second display can end up seriously slowing you down.</p> - -<p>One of the most effective things you can do to speed up this process is build multiple bundles - one for your application code and one for your dependencies. When your application code changes you only have to recompile that bundle, not all of your dependencies.</p> - -<h2>On the command line</h2> - -<p>If you&#39;re using the command line interface, creating an additional bundle is as easy as invoking <em>browserify</em> with the <em>--require</em> option. You don&#39;t have to point it at a source file, you can simply pass <em>-r my-module</em> for each module you want to include in the bundle. This will pull the requirement into the bundle and make that requirement available from outside the bundle with <code data-syntax="text-only">require(&#39;my-module&#39;)</code>.</p> - -<pre class="highlight"><code data-syntax="text-only">$ browserify -r react -r q -r loglevel &gt; build/vendor.js</code></pre> - -<p>If you include <em>vendor.js</em> from the example in your HTML, you can then <code data-syntax="text-only">require(&#39;react&#39;)</code> or <code data-syntax="text-only">require(&#39;q&#39;)</code> from anywhere. You may notice, however, that your application bundle is still pulling these requirements in, defeating the whole purpose. This brings us to the next command line option we need to use, <em>--external</em>. </p> - -<p>The <em>--external</em> option tells browserify that the given module will be provided externally and doesn&#39;t need to be included in this bundle. When used with your application bundle, it will filter out the dependencies that you will be compiling into your vendor bundle.</p> - -<pre class="highlight"><code data-syntax="text-only">$ browserify -x react -x q -x loglevel src/index.js &gt; build/app.js</code></pre> - -<p>Make sure to include the <em>vendor.js</em> file <strong>before</strong> <em>app.js</em> in your HTML, so that the dependencies will be available when <em>app.js</em> is loaded.</p> - -<h2>With Gulp</h2> - -<p><a href="https://github.com/gulpjs/gulp">Gulp</a> has recently overtaken <a href="http://gruntjs.com/">Grunt</a> as our task manager of choice. We typically set Gulp up with our major tasks in a <em>gulp/</em> subfolder, and then we require each of those modules in our <em>gulpfile.js</em>:</p> - -<pre class="highlight"><code data-syntax="text-only">&#39;use strict&#39;; -var gulp = require(&#39;gulp&#39;); - -require(&#39;./gulp/app&#39;); -require(&#39;./gulp/serve&#39;); -require(&#39;./gulp/vendor&#39;); -require(&#39;./gulp/watch&#39;); - -gulp.task(&#39;build&#39;, [ - &#39;app&#39;, - &#39;vendor&#39;, -]); - -gulp.task(&#39;default&#39;, [&#39;build&#39;], function() { - return gulp.start(&#39;serve&#39;, &#39;watch&#39;); -});</code></pre> - -<h3>The vendor bundle</h3> - -<p>I&#39;ll start with our vendor bundle, and break it up to explain a few things.</p> - -<pre class="highlight"><code data-syntax="text-only">&#39;use strict&#39;; -var browserify = require(&#39;gulp-browserify&#39;); -var gulp = require(&#39;gulp&#39;); -var rename = require(&#39;gulp-rename&#39;); -var uglify = require(&#39;gulp-uglify&#39;); - -var libs = [ - &#39;react&#39;, - &#39;react/lib/ReactCSSTransitionGroup&#39;, - &#39;react/lib/cx&#39;, - &#39;q&#39;, - &#39;underscore&#39;, - &#39;loglevel&#39; -];</code></pre> - -<p>I assign an array of dependency names to a variable, because we&#39;ll be using this in a couple of places.</p> - -<pre class="highlight"><code data-syntax="text-only">gulp.task(&#39;vendor&#39;, function() { - var production = (process.env.NODE_ENV === &#39;production&#39;);</code></pre> - -<p>I&#39;m using the NODE_ENV environment variable to determine whether this is a production build or not.</p> - -<pre class="highlight"><code data-syntax="text-only">// A dummy entry point for browserify - var stream = gulp.src(&#39;./gulp/noop.js&#39;, {read: false})</code></pre> - -<p>Since Gulp is a file-based build system, it needs a file to open the stream with. We don&#39;t really need this on the vendor bundle, so my workaround is to point it to an empty file called <em>noop.js</em>.</p> - -<pre class="highlight"><code data-syntax="text-only">// Browserify it - .pipe(browserify({ - debug: false, // Don&#39;t provide source maps for vendor libs - })) - - .on(&#39;prebundle&#39;, function(bundle) { - // Require vendor libraries and make them available outside the bundle. - libs.forEach(function(lib) { - bundle.require(lib); - }); - });</code></pre> - -<p>This is where the magic happens. The <a href="https://github.com/deepak1556/gulp-browserify">gulp-browserify</a> plugin doesn&#39;t have an option to handle the <em>--require</em> command, so I simply listen for the &quot;prebundle&quot; event that it sends, and interact with browserify&#39;s API directly. The <code data-syntax="text-only">bundle.require()</code> method is documented <a href="https://github.com/substack/node-browserify#brequirefile-opts">here</a>. I iterate over the list of dependencies, and call <code data-syntax="text-only">bundle.require()</code> for each one.</p> - -<pre class="highlight"><code data-syntax="text-only">if (production) { - // If this is a production build, minify it - stream.pipe(uglify()); - } - - // Give the destination file a name, adding &#39;.min&#39; if this is production - stream.pipe(rename(&#39;vendor&#39; + (production ? &#39;.min&#39; : &#39;&#39;) + &#39;.js&#39;)) - - // Save to the build directory - .pipe(gulp.dest(&#39;build/&#39;)); - - return stream; - -}); - -exports.libs = libs;</code></pre> - -<p>The rest of the task is pretty basic. I minify it if this is a production build, give the bundle an appropriate name, and save it to the build directory. I assign the list of dependencies to <code data-syntax="text-only">exports.libs</code> so that it will be available to other modules, like our application bundle.</p> - -<h3>The application bundle</h3> - -<p>The application bundle follows a very similar pattern:</p> - -<pre class="highlight"><code data-syntax="text-only">&#39;use strict&#39;; -var browserify = require(&#39;gulp-browserify&#39;); -var gulp = require(&#39;gulp&#39;); -var libs = require(&#39;./vendor&#39;).libs; -var pkg = require(&#39;../package.json&#39;); -var rename = require(&#39;gulp-rename&#39;); -var uglify = require(&#39;gulp-uglify&#39;);</code></pre> - -<p>I import the list of dependencies that I exported from the vendor bundle with <code data-syntax="text-only">require(&#39;./vendor&#39;).libs</code>.</p> - -<pre class="highlight"><code data-syntax="text-only">gulp.task(&a |