<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/zeit/next.js/issues?q=is%3Aissue">issues</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h2 dir="auto">Expected Behavior</h2>
<p dir="auto">When running <code class="notranslate">NODE_ENV=staging next build</code> I expect the <code class="notranslate">.next</code> folder to be generated with "staging" as <code class="notranslate">process.env.NODE_ENV</code> but I get "production" instead.</p>
<h2 dir="auto">Steps to Reproduce (for bugs)</h2>


<ol dir="auto">
<li>Run <code class="notranslate">NODE_ENV=staging next build</code></li>
</ol>
<h2 dir="auto">Your Environment</h2>

<table role="table">
<thead>
<tr>
<th>Tech</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<tr>
<td>next</td>
<td>5.0.1-canary.14</td>
</tr>
<tr>
<td>node</td>
<td>6.10</td>
</tr>
</tbody>
</table>
<h1 dir="auto">Feature request</h1>
<h2 dir="auto">Is your feature request related to a problem? Please describe.</h2>
<p dir="auto">There are many different methods of codebase organization in the wild and one popular one is to use an <code class="notranslate">index.js</code> file for the page component itself and surround it with sibling files for various subviews that are specific to that page.</p>
<p dir="auto">However, next doesn't support this kind of structure because it automatically assumes <em>all</em> files inside of <code class="notranslate">pages/</code> are real pages.</p>
<h2 dir="auto">Describe the solution you'd like</h2>
<p dir="auto">There already is precedent in the codebase for convention over configuration when it comes to filenaming:</p>
<ul dir="auto">
<li>the <code class="notranslate">[id].js</code> pattern for dynamic routing</li>
<li>the <code class="notranslate">_(app|document|error).js</code> pattern for overriding built-in pages</li>
</ul>
<p dir="auto">I propose extending the leading-underscore naming pattern such that any file inside <code class="notranslate">pages/</code> prefixed with an underscore will not be considered as a public page and can simply live in the folder.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="pages/
  index.js                  &lt;- page
  accounts/
    index.js                &lt;- page
    _constants.js           &lt;- not a page
    _modal.js               &lt;- not a page"><pre class="notranslate"><code class="notranslate">pages/
  index.js                  &lt;- page
  accounts/
    index.js                &lt;- page
    _constants.js           &lt;- not a page
    _modal.js               &lt;- not a page
</code></pre></div>
<h2 dir="auto">Describe alternatives you've considered</h2>
<p dir="auto">Another prefix I thought of was "$", e.g. <code class="notranslate">$constants.js</code> but this felt a little strange to write and actually is <a href="https://en.wikipedia.org/wiki/Filename" rel="nofollow">not supported in some filesystems</a>.</p>