You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

707 lines
31 KiB

8 years ago
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Simple · Neutrino</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.2">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="advanced.html" />
<link rel="prev" href="./" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../installation.html">
<a href="../installation.html">
Installation
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../usage.html">
<a href="../usage.html">
Usage
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../project-layout.html">
<a href="../project-layout.html">
Project Layout
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../presets/">
<a href="../presets/">
Presets
</a>
<ul class="articles">
<li class="chapter " data-level="1.5.1" data-path="../presets/neutrino-preset-web/">
<a href="../presets/neutrino-preset-web/">
8 years ago
Web
8 years ago
</a>
</li>
<li class="chapter " data-level="1.5.2" data-path="../presets/neutrino-preset-react/">
<a href="../presets/neutrino-preset-react/">
8 years ago
React
8 years ago
</a>
</li>
<li class="chapter " data-level="1.5.3" data-path="../presets/neutrino-preset-node/">
<a href="../presets/neutrino-preset-node/">
8 years ago
Node.js
8 years ago
</a>
</li>
8 years ago
<li class="chapter " data-level="1.5.4" data-path="../presets/neutrino-preset-airbnb-base/">
8 years ago
8 years ago
<a href="../presets/neutrino-preset-airbnb-base/">
8 years ago
8 years ago
Airbnb
8 years ago
</a>
</li>
8 years ago
<li class="chapter " data-level="1.5.5" data-path="../presets/neutrino-preset-karma/">
8 years ago
8 years ago
<a href="../presets/neutrino-preset-karma/">
8 years ago
8 years ago
Karma
8 years ago
</a>
</li>
8 years ago
<li class="chapter " data-level="1.5.6" data-path="../presets/neutrino-preset-mocha/">
8 years ago
8 years ago
<a href="../presets/neutrino-preset-mocha/">
8 years ago
8 years ago
Mocha
8 years ago
</a>
</li>
8 years ago
<li class="chapter " data-level="1.5.7" data-path="../presets/neutrino-preset-jest/">
8 years ago
8 years ago
<a href="../presets/neutrino-preset-jest/">
8 years ago
8 years ago
Jest
8 years ago
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.6" data-path="./">
<a href="./">
Customization
</a>
<ul class="articles">
<li class="chapter active" data-level="1.6.1" data-path="simple.html">
<a href="simple.html">
Simple
</a>
</li>
<li class="chapter " data-level="1.6.2" data-path="advanced.html">
<a href="advanced.html">
Advanced
</a>
</li>
</ul>
</li>
8 years ago
<li class="chapter " data-level="1.7" data-path="../creating-presets.html">
8 years ago
8 years ago
<a href="../creating-presets.html">
8 years ago
Creating presets
</a>
</li>
<li class="chapter " data-level="1.8" data-path="../api/">
<a href="../api/">
API
</a>
</li>
<li class="chapter " data-level="1.9" data-path="../cli/">
<a href="../cli/">
CLI
</a>
</li>
<li class="chapter " data-level="1.10" data-path="../contributing/">
<a href="../contributing/">
Contributing
</a>
<ul class="articles">
8 years ago
<li class="chapter " data-level="1.10.1" data-path="../contributing/development.html">
8 years ago
8 years ago
<a href="../contributing/development.html">
8 years ago
8 years ago
Development Process
8 years ago
</a>
</li>
8 years ago
<li class="chapter " data-level="1.10.2" data-path="../contributing/code-of-conduct.html">
8 years ago
8 years ago
<a href="../contributing/code-of-conduct.html">
8 years ago
8 years ago
Code of Conduct
8 years ago
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >Simple</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="simple-neutrino-customization">Simple Neutrino Customization</h1>
<p>No two JavaScript projects are ever the same, and as such there may be times when you will need to make modifications
to the way your Neutrino preset is building your project. By defining a configuration object within your package.json,
Neutrino will merge this information with that provided by your preset, effectively overriding those options with your
custom data.</p>
<h2 id="prepare-packagejson">Prepare package.json</h2>
<p>First, you will need to define a <code>config</code> section within your package.json. You
<a href="../usage.html#using-multiple-presets">may have already done this</a> if you
specified your presets through the <code>config</code> as opposed to flags through <code>scripts</code>:</p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
<span class="token property">&quot;config&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;presets&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
<span class="token string">&quot;neutrino-preset-react&quot;</span><span class="token punctuation">,</span>
<span class="token string">&quot;neutrino-preset-karma&quot;</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token property">&quot;scripts&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;start&quot;</span><span class="token operator">:</span> <span class="token string">&quot;neutrino start&quot;</span><span class="token punctuation">,</span>
<span class="token property">&quot;build&quot;</span><span class="token operator">:</span> <span class="token string">&quot;neutrino build&quot;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Add a new property to <code>config</code> named <code>neutrino</code>. This will be an object where we can provide configuration data:</p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
<span class="token property">&quot;config&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;presets&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token property">&quot;neutrino&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Populate this object with configuration overrides. This is not a Webpack configuration, but rather a Neutrino-compatible
object based on <a href="https://github.com/mozilla-rpweb/webpack-chain" target="_blank">webpack-chain</a>.</p>
<h2 id="usage">Usage</h2>
<h3 id="entries">Entries</h3>
<p>Add files to named entry points, or define new entry points. This is a key named <code>entry</code>, with a value being an object.
This maps to points to enter the application. At this point the application starts executing.</p>
<p><em>Example: Define an entry point named <code>vendor</code> that bundles React packages separately from the application code.</em></p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
<span class="token property">&quot;config&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;neutrino&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;entry&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;vendor&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
<span class="token string">&quot;react&quot;</span><span class="token punctuation">,</span>
<span class="token string">&quot;react-dom&quot;</span><span class="token punctuation">,</span>
<span class="token string">&quot;react-hot-loader&quot;</span><span class="token punctuation">,</span>
<span class="token string">&quot;react-router-dom&quot;</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h3 id="module">Module</h3>
<p>The <code>module</code> object defines how the different types of modules within a project will be treated. Any additional
properties attached to <code>module</code> not defined below will be set on the final module configuration.</p>
<h4 id="module-rules">Module Rules</h4>
<p>Using <code>module.rule</code> creates rules that are matched to requests when modules are created. These rules can modify how the
module is created. They can apply loaders to the module, or modify the parser. </p>
<p>Using <code>module.rule.loader</code> allows to you define the Webpack loader and its options for processing a particular rule.
This loader is usually a <code>dependency</code> or <code>devDependency</code> of your project. Each <code>loader</code> object can specify a property
for the string <code>loader</code> and an <code>options</code> object.</p>
<p><em>Example: Add LESS loading to the project.</em></p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
<span class="token property">&quot;dependencies&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;less&quot;</span><span class="token operator">:</span> <span class="token string">&quot;^2.7.2&quot;</span><span class="token punctuation">,</span>
<span class="token property">&quot;less-loader&quot;</span><span class="token operator">:</span> <span class="token string">&quot;^2.2.3&quot;</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token property">&quot;config&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;neutrino&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;module&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;rule&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;styles&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;test&quot;</span><span class="token operator">:</span> <span class="token string">&quot;/\\.less$/&quot;</span><span class="token punctuation">,</span>
<span class="token property">&quot;loader&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;less&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;loader&quot;</span><span class="token operator">:</span> <span class="token string">&quot;less-loader&quot;</span><span class="token punctuation">,</span>
<span class="token property">&quot;options&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;noIeCompat&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h3 id="output">Output</h3>
<p>The <code>output</code> object contains a set of options instructing Webpack on how and where it should output your bundles,
assets, and anything else you bundle or load with Webpack. This option can be any property/value combination that
<a href="https://webpack.js.org/configuration/output/" target="_blank">Webpack accepts</a>.</p>
<p><em>Example: Change the public path of the application.</em></p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
<span class="token property">&quot;config&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;neutrino&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;output&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;publicPath&quot;</span><span class="token operator">:</span> <span class="token string">&quot;https://cdn.example.com/assets/&quot;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h3 id="node">Node</h3>
<p>Use <code>node</code> to customize the Node.js environment using polyfills or mocks:</p>
<p><em>Example: mock the <code>__filename</code> and <code>__dirname</code> Node.js globals.</em></p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
<span class="token property">&quot;config&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;neutrino&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;node&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;__filename&quot;</span><span class="token operator">:</span> <span class="token string">&quot;mock&quot;</span><span class="token punctuation">,</span>
<span class="token property">&quot;__dirname&quot;</span><span class="token operator">:</span> <span class="token string">&quot;mock&quot;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h3 id="devserver">DevServer</h3>
<p>Use <code>devServer</code> to customize webpack-dev-server and change its behavior in various ways.</p>
<p><em>Example: gzip the application when serving and listen on port 9000.</em></p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
<span class="token property">&quot;config&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;neutrino&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;devServer&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;compress&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
<span class="token property">&quot;port&quot;</span><span class="token operator">:</span> <span class="token number">9000</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h3 id="resolve">Resolve</h3>
<p>Use <code>resolve</code> to change how modules are resolved. When using <code>resolve.extensions</code> and <code>resolve.modules</code>, these should be
specified as arrays, and will be merged with their respective definitions used in inherited presets. Any additional
properties attached to <code>resolve</code> not defined below will be set on the final module configuration.</p>
<p><em>Example: Add <code>.mjs</code> as a resolving extension and specify modules are located in a <code>custom_modules</code> directory.</em></p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
<span class="token property">&quot;config&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;neutrino&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;resolve&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;extensions&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;.mjs&quot;</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token property">&quot;modules&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;custom_modules&quot;</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h3 id="resolveloader">ResolveLoader</h3>
<p>Use <code>resolveLoader</code> to change how loader packages are resolved. When using <code>resolveLoader.extensions</code> and
<code>resolveLoader.modules</code>, these should be specified as arrays, and will be merged with their respective definitions used
in inherited presets. Any additional properties attached to <code>resolveLoader</code> not defined below will be set on the final
module configuration.</p>
<p><em>Example: Add <code>.loader.js</code> as a loader extension and specify modules are located in a <code>web_loaders</code> directory.</em></p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
<span class="token property">&quot;config&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;neutrino&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;resolve&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;extensions&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;.loader.js&quot;</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token property">&quot;modules&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;web_loaders&quot;</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h3 id="additional-configuration">Additional configuration</h3>
<p>Any top-level properties you set on <code>config.neutrino</code> will be added to the configuration.</p>
<p><em>Example: Change the Webpack performance options to error when exceeding performance budgets.</em></p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
<span class="token property">&quot;config&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;neutrino&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;performance&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">&quot;hints&quot;</span><span class="token operator">:</span> <span class="token string">&quot;error&quot;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="advanced-configuration">Advanced Configuration</h2>
<p>With the options defined above in your package.json, you can perform a variety of build customizations on a per-project
basis. In the event that you need more customization than what is afforded through JSON, consider either switching to
8 years ago
<a href="advanced.html">advanced configuration</a>, or <a href="../creating-presets.html">creating your own preset</a>.</p>
8 years ago
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="./" class="navigation navigation-prev " aria-label="Previous page: Customization">
<i class="fa fa-angle-left"></i>
</a>
<a href="advanced.html" class="navigation navigation-next " aria-label="Next page: Advanced">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
8 years ago
gitbook.page.hasChanged({"page":{"title":"Simple","level":"1.6.1","depth":2,"next":{"title":"Advanced","level":"1.6.2","depth":2,"path":"customization/advanced.md","ref":"customization/advanced.md","articles":[]},"previous":{"title":"Customization","level":"1.6","depth":1,"path":"customization/README.md","ref":"customization/README.md","articles":[{"title":"Simple","level":"1.6.1","depth":2,"path":"customization/simple.md","ref":"customization/simple.md","articles":[]},{"title":"Advanced","level":"1.6.2","depth":2,"path":"customization/advanced.md","ref":"customization/advanced.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["edit-link","prism","-highlight","github","anchorjs"],"root":"./docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{},"github":{"url":"https://github.com/mozilla-neutrino/neutrino-dev/"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit page","base":"https://github.com/mozilla-neutrino/neutrino-dev/tree/master/docs"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchorjs":{}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Neutrino","gitbook":"*"},"file":{"path":"customization/simple.md","mtime":"2017-02-16T18:32:52.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-02-21T19:05:42.839Z"},"basePath":"..","book":{"language":""}});
8 years ago
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/3.1.1/anchor.min.js"></script>
<script src="../gitbook/gitbook-plugin-anchorjs/anchor-style.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
</body>
</html>