From eead31a87e18c52ac46a197086e98682b2bae90a Mon Sep 17 00:00:00 2001 From: Jonny Buchanan Date: Fri, 8 Jul 2016 01:32:18 +1000 Subject: [PATCH] Add a --preact flag to enable a preact-compat build - 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 --- CHANGES.md | 1 + docs/Commands.md | 2 +- src/commands/build-react-app.js | 11 ++++++++++- src/commands/build-react.js | 11 ++++++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index aa512e8f..cd69040c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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:** diff --git a/docs/Commands.md b/docs/Commands.md index 7c7d0a65..1f53bcf5 100644 --- a/docs/Commands.md +++ b/docs/Commands.md @@ -66,6 +66,7 @@ react build [dist_dir] [options] - `--mount-id` - `id` for the `
` the app will render into *[default: app]* - `--title` - contents for `` *[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` @@ -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/` diff --git a/src/commands/build-react-app.js b/src/commands/build-react-app.js index ab46c12d..5c777799 100644 --- a/src/commands/build-react-app.js +++ b/src/commands/build-react-app.js @@ -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: { diff --git a/src/commands/build-react.js b/src/commands/build-react.js index 9f41335e..6f62790f 100644 --- a/src/commands/build-react.js +++ b/src/commands/build-react.js @@ -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'