npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

neutrino-preset-mozilla-rpweb

v5.0.1

Published

[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url]

Downloads

17

Readme

Mozilla R&P Web Neutrino React Preset

NPM version NPM downloads Join Slack

neutrino-preset-mozilla-rpweb is a Neutrino preset that supports building React web applications and linting them with Airbnb's base ESLint config, following the Airbnb styleguide with Mozilla additions. This preset is used for web projects within Mozilla's former Release and Productivity team.

Features

  • Extends from neutrino-preset-react
  • Zero upfront configuration necessary to start developing and building a React web app
  • Modern Babel compilation adding JSX and object rest spread syntax.
  • Support for React Hot Loader
  • Write JSX in .js or .jsx files
  • Extends from neutrino-preset-web
    • Modern Babel compilation supporting ES modules, last 2 major browser versions, async functions, and dynamic imports
    • Webpack loaders for importing HTML, CSS, images, icons, and fonts
    • Webpack Dev Server during development
    • Automatic creation of HTML pages, no templating necessary
    • Hot module replacement support
    • Production-optimized bundles with Babili minification and easy chunking
    • Easily extensible to customize your project as needed

Extends from neutrino-preset-airbnb-base

  • Zero upfront configuration necessary to start linting your project
  • Modern Babel knowledge supporting ES modules, JSX, and React apps
  • Highly visible during development, fails compilation when building for production
  • Easily extensible to customize your project as needed

Requirements

  • Node.js v6.10+
  • Yarn or npm client
  • Neutrino v6

Installation

neutrino-preset-mozilla-rpweb can be installed via the Yarn or npm clients. Inside your project, make sure neutrino and neutrino-preset-rpweb are development dependencies. You will also need React and React DOM for actual React development. Yarn is highly preferred for Mozilla web projects.

Yarn

❯ yarn add --dev neutrino neutrino-preset-mozilla-rpweb
❯ yarn add react react-dom

npm

❯ npm install --save-dev neutrino neutrino-preset-mozilla-rpweb
❯ npm install --save react react-dom

Project Layout

neutrino-preset-mozilla-rpweb follows the standard project layout specified by Neutrino. This means that by default all project source code should live in a directory named src in the root of the project. This includes JavaScript files, CSS stylesheets, images, and any other assets that would be available to import your compiled project.

Quickstart

After installing Neutrino and the this preset, add a new directory named src in the root of the project, with a single JS file named index.js in it.

❯ mkdir src && touch src/index.js

This React preset exposes an element in the page with an ID of root to which you can mount your application. Edit your src/index.js file with the following:

import React from 'react';
import { render } from 'react-dom';

render(<h1>Hello world!</h1>, document.getElementById('root'));

Now edit your project's package.json to add commands for starting and building the application:

{
  "scripts": {
    "start": "neutrino start --use neutrino-preset-mozilla-rpweb",
    "build": "neutrino build --use neutrino-preset-mozilla-rpweb"
  }
}

If you are using .neutrinorc.js, add this preset to your use array instead of --use flags:

module.exports = {
  use: ['neutrino-preset-mozilla-rpweb']
};

Start the app, then open a browser to the address in the console:

Yarn

❯ yarn start
✔ Development server running on: http://localhost:5000
✔ Build completed

npm

❯ npm start
✔ Development server running on: http://localhost:5000
✔ Build completed

Building

neutrino-preset-mozilla-rpweb builds static assets to the build directory by default when running neutrino build. Using the quick start example above as a reference:

❯ yarn build

✔ Building project completed
Hash: b26ff013b5a2d5f7b824
Version: webpack 2.6.1
Time: 9773ms
                           Asset       Size    Chunks             Chunk Names
   index.dfbad882ab3d86bfd747.js     181 kB     index  [emitted]  index
polyfill.57dabda41992eba7552f.js    69.2 kB  polyfill  [emitted]  polyfill
 runtime.3d9f9d2453f192a2b10f.js    1.51 kB   runtime  [emitted]  runtime
                      index.html  846 bytes            [emitted]
✨  Done in 14.62s.

You can either serve or deploy the contents of this build directory as a static site.

Static assets

If you wish to copy files to the build directory that are not imported from application code, you can place them in a directory within src called static. All files in this directory will be copied from src/static to build/static.

Paths

The neutrino-preset-web preset loads assets relative to the path of your application by setting Webpack's output.publicPath to ./. If you wish to load assets instead from a CDN, or if you wish to change to an absolute path for your application, customize your build to override output.publicPath. See the Customizing section below.

Preset options

You can provide custom options and have them merged with this preset's default options to easily affect how this preset builds. You can modify the React and ESLint preset settings from .neutrinorc.js by overriding with an options object. Use an array pair instead of a string to supply these options in .neutrinorc.js.

The following shows how you can pass an options object to this preset and override its options. See the Web documentation or Airbnb ESLint documentation for specific options you can override with this object.

module.exports = {
  use: [
    ['neutrino-preset-mozilla-rpweb', {
      eslint: {
        rules: {
          semi: 'off'
        }
      },
      react: {
        // Example: disable Hot Module Replacement
        hot: false,
  
        // Example: change the page title
        html: {
          title: 'Epic React App'
        }
      }
    }]
  ]
};

Customizing

To override the build configuration, start with the documentation on customization. neutrino-preset-mozilla-rpweb does not use any additional named rules, loaders, or plugins that aren't already in use by the Web preset. See the Web documentation customization for preset-specific configuration to override.

Overriding configuration

By following the customization guide and knowing the rule, loader, and plugin IDs from neutrino-preset-web, you can override and augment the build by providing a function to your .neutrinorc.js use array. You can also make these changes from the Neutrino API in custom middleware.

Vendoring

By defining an entry point named vendor you can split out external dependencies into a chunk separate from your application code.

Example: Put React and React DOM into a separate "vendor" chunk:

module.exports = {
  use: [
    'neutrino-preset-mozilla-rpweb',
    (neutrino) => neutrino.config
      .entry('vendor')
        .add('react')
        .add('react-dom')
  ]
};

Hot Module Replacement

While neutrino-preset-react supports Hot Module Replacement your app using React Hot Loader, it does require some application-specific changes in order to operate.

First, install react-hot-loader as a dependency, this must be React Hot Loader v3+ (currently in beta):

Yarn

❯ yarn add react-hot-loader@next

npm

❯ npm install --save react-hot-loader@next

  • From your index entry point (defaults to src/index.* from neutrino.options.entry), import an AppContainer from react-hot-loader. The main file may be named index.js or index.jsx. The extension is resolved by Webpack.
  • Wrap your top-level React component in the AppContainer.
  • Perform the application render in a reusable function for initial load and subsequent reloads.
  • Add the hot acceptance to call this function.

For example:

import React from 'react';
import { render } from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import MyApp from './MyApp';

const load = () => render((
  <AppContainer>
    <MyApp />
  </AppContainer>
), document.getElementById('root'));

if (module.hot) {
  module.hot.accept('./MyApp', load);
}

load();