Skip to content

Commit

Permalink
Add a --preact flag to enable a preact-compat build
Browse files Browse the repository at this point in the history
- react and react-dom are aliased to preact-compat in Webpack config
- Incompatible Babel transforms for React production optimisations are excluded from Babel config

Closes #124
  • Loading branch information
insin committed Jul 16, 2016
1 parent ef96933 commit eead31a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**Added:**

- Added a `--preact` flag to React app builds to create a [preact-compat](https://github.com/developit/preact-compat)-compatible build. This is a drop-in way to try [preact](https://github.com/developit/preact) with your React app [[#124](https://github.com/insin/nwb/issues/124)]
- `webpack.compat` now supports `'json-schema': true` to prevent a transitive `json-schema` dependency breaking Webpack builds.

**Changed:**
Expand Down
2 changes: 1 addition & 1 deletion docs/Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ react build <entry> [dist_dir] [options]

- `--mount-id` - `id` for the `<div>` the app will render into *[default: app]*
- `--title` - contents for `<title>` *[default: React App]*
- `--preact` - create a [preact-compat](https://github.com/developit/preact-compat#usage-with-webpack)-compatible build
- `--vendor` - create a separate vendor bundle

### `nwb`
Expand Down Expand Up @@ -233,7 +234,6 @@ Builds the component in preparation for publishing to npm.

Passing an argument for `entry` allows you to customise the entry point for the UMD build of your app.


- An ES5 build will be created in `lib/`
- If enabled, UMD builds will be created in `umd/`
- If enabled, ES6 modules builds will be created in `es6/`
Expand Down
11 changes: 10 additions & 1 deletion src/commands/build-react-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ let buildConfig = (args) => {
}
}

if (process.env.NODE_ENV === 'production') {
if (args.preact) {
config.resolve = {
alias: {
'react': 'preact-compat',
'react-dom': 'preact-compat'
}
}
}

if (process.env.NODE_ENV === 'production' && !args.preact) {
config.loaders = {
babel: {
query: {
Expand Down
11 changes: 10 additions & 1 deletion src/commands/build-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ let buildConfig = (args) => {
}
}

if (process.env.NODE_ENV === 'production') {
if (args.preact) {
config.resolve = {
alias: {
'react': 'preact-compat',
'react-dom': 'preact-compat'
}
}
}

if (process.env.NODE_ENV === 'production' && !args.preact) {
config.loaders.babel.query.optional = [
'optimisation.react.inlineElements',
'optimisation.react.constantElements'
Expand Down

0 comments on commit eead31a

Please sign in to comment.