# react-noparse

> Helper for using webpack noParse/alias with react

Latest version **0.0.1** (published 2016-04-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-noparse
pnpm add react-noparse
yarn add react-noparse
bun add react-noparse
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2016-04-25 |
| First published | 2016-04-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=5.0.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Justin Greenberg |
| Maintainers | justinkgreenberg |
| Keywords | react, webpack, alias, noparse, config, optimize |

## Links

- npm: https://www.npmjs.com/package/react-noparse
- Repository: https://github.com/justingreenberg/react-noparse
- Homepage: https://github.com/justingreenberg/react-noparse#readme
- Issues: https://github.com/justingreenberg/react-noparse/issues
- npm.io page: https://npm.io/package/react-noparse

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2016-04-25

## README

# react-noparse
[![Build Status][ci-image]][ci-url]
[![Coverage Status][cov-image]][cov-url]
[![NPM version][npm-image]][npm-url]

**:warning: _Experimental_**

This is a webpack configuration helper that aims to improve build times by providing an simple way to exclude large dependencies in development environments. Instead of having webpack load and parse the entire module (and dependency tree), we just use the distributable UMD build instead, like loading from a CDN except it's right on our disk.

I wanted to make this extremely easy to drop into your project, quickly evaluate the impact and remove just as easily.

**This tool can be added with a single line of code and removed just as easily.** The [source][index-url] is extensively commented, and the [tests][tests-url] demonstrate the  different configuration options.

#### How it works:

There are several steps to setting up this configuration:

0. Tell webpack to exclude the module (see [`module.noParse`][noparse-url])
0. Configure a resolver, so we can still use `require` and `import` (see [`resolve.alias`][alias-url])
0. Optionally expose `React`, if needed (see [`imports-loader`][imports-loader-url])

This module returns a function that will handle the above mutations on your webpack configuration.

## Installation

```sh
npm install --save-dev react-noparse
```

## Basic Usage

Please see the [tests][tests-url] and [example][example-url]. Adding `react-noparse` to your project is dead simple:

```js
const path = require('path')
const webpack = require('webpack')
const noParse = require('react-noparse').noParse   // 1. Grab module

const config = {
  devtool: 'cheap-module-eval-source-map',
  entry: [
    'webpack-hot-middleware/client',
    './src/index'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    publicPath: '/dist/'
  },
  plugins: [
    webpack.HotModuleReplacementPlugin(),
    webpack.NoErrorsPlugin()
  ],
  module: {
    loader: [{
      test: /\.js$/,
      loaders: ['babel'],
      include: path.join(__dirname, 'src')
    }]
  }
}

module.exports = noParse(true)(config)  // 2. Use defaults: React, ReactDOM, ReactRouter

// 3. That's it!
```

##### Output:

```js

{
  devtool: 'cheap-module-eval-source-map',
  entry: [
    'webpack-hot-middleware/client',
    './src/index'
  ],
  output: {
    path: '<path-to-project>/dist',
    filename: 'bundle.js',
    publicPath: '/dist/'
  },
  plugins: [ 
    webpack.HotModuleReplacementPlugin(),
    webpack.NoErrorsPlugin()
  ],
  module: {
    loaders: [{
      test: /\.js$/,
      loader: ['babel'],
      include: '<path-to-project>/src' 
    }, {
      test: /(react-dom|react-router)\.js$/, // expose React
      loader: 'imports?React=react'
    }],
    noParse: [
      /\/react\//g,
      /\/react-dom\//g,
      /\/react-router\//g
    ]
  },
  resolve: {
    alias: {
      'react$': '/node_modules/react/dist/react.js',
      'react-dom$': '/node_modules/react-dom/dist/react-dom.js',
      'react-router$': '/node_modules/react-router/umd/ReactRouter.js'
    }
  }
}

```

## Configuration

In the example above we're using a shorcut syntax with <a href="#noparse">`noParse`</a> by passing `true`, which uses the built-in <a href="#defaults">`defaults`</a> object:

```js
// ...
module.exports = noParse([
  React: {
    distPath: 'react/dist/react.js',
  },
  ReactDOM: {
    distPath: 'react-dom/dist/react-dom.js',
    importReact: true
  },
  ReactRouter: {
    distPath: 'react-router/umd/ReactRouter.js',
    importReact: true
  }
])(config)

```

The defaults can be used individually, for example if you only needed React + ReactDOM:
```js
const defaults = required('react-noparse').defaults
// ...
module.exports = noParse([
  defaults.React,
  defaults.ReactDOM
])(config)

```

## Notes

- the `distPath` _must_ point to a UMD build
- you cannot `import x from 'module/x'`, you must `import { x } from 'module'`

## API

<dl>
<dt><a name="noparse"><code>noParse(libs, useMin)</code></a> : <code>mutatorFn(WebpackConfig)</code> : <code>WebpackConfig</code></dt>
<dd><p>Process libs and return a function that accepts a webpack configuration and appliesmutatations</p>
</dd>
</dl>

| Param | Type | Description |
| --- | --- | --- |
| `libs` | `bool` &#124; `Array<Object>` &#124; `Array<String>` | All, Path, or Array of Paths(s) to UMD builds |
| `libs[].distPath` | `string` | String of path to dist (required) |
| `libs[].importReact` | `boolean` | Whether or not to expose react |
| `useMin` | `boolean` | Use minified (default=`true` in `production`) |

<dl>
<dt><a name="defaults"><code>defaults</code></a> : <code>Object</code></dt>
<dd><p>Provide some common configuration defaults:
<ul>
<li><code>React</code>: <code>{ distPath: 'react/dist/react.js' }</code></li>
<li><code>ReactDOM</code>: <code>{ distPath: 'react-dom/dist/react-dom.js', importReact: true }</code></li>
<li><code>ReactRouter</code>: <code>{ distPath: 'react-router/umd/ReactRouter.js', importReact: true }</code></li>
</ul>
</p>
</dd>
</dl>

<hr>

&copy; 2016 [Justin Greenberg][justin-url] &nbsp; MIT License


[ci-image]: https://travis-ci.org/justingreenberg/react-noparse.svg?branch=master
[ci-url]: https://travis-ci.org/justingreenberg/react-noparse
[cov-image]: http://coveralls.io/repos/github/justingreenberg/react-noparse/badge.svg?branch=master
[cov-url]: http://coveralls.io/github/justingreenberg/react-noparse?branch=master
[npm-image]: https://img.shields.io/npm/v/react-noparse.svg?style=flat
[npm-url]: https://npmjs.org/package/react-noparse

[alias-url]: https://webpack.github.io/docs/configuration.html#resolve-alias
[noparse-url]: https://webpack.github.io/docs/configuration.html#module-noparse
[imports-loader-url]: https://github.com/webpack/imports-loader

[index-url]: https://github.com/justingreenberg/react-noparse/blob/master/index.js
[example-url]: https://github.com/justingreenberg/react-noparse/blob/master/example.js
[tests-url]: https://github.com/justingreenberg/react-noparse/blob/master/test.js
[justin-url]: https://www.justingreenberg.com

---
_Source: https://npm.io/package/react-noparse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
