Skip to content

Commit

Permalink
Merge pull request #727 from psabharwal123/Flag-to-enable-react-hot-l…
Browse files Browse the repository at this point in the history
…oader

Flag to enable react hot loader with default set to false
  • Loading branch information
ForsakenHarmony authored Feb 12, 2019
2 parents 3c1caed + 2f4e14e commit b8ac82b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ $ preact watch
--host, Hostname to start a server on [string] [default: "0.0.0.0"]
--https Use HTTPS? [boolean] [default: false]
--prerender Pre-render static app content on initial build [boolean] [default: false]
--rhl Enable react hot loader [boolean] [default: false]
```

Note:
Expand Down
1 change: 1 addition & 0 deletions packages/cli/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ prog
.option('--src', 'Specify source directory', 'src')
.option('--cwd', 'A directory to use instead of $PWD', '.')
.option('--sw', 'Generate and attach a Service Worker', false)
.option('--rhl', 'Enable react hot loader', false)
.option('--json', 'Generate build stats for bundle analysis')
.option('--https', 'Run server with HTTPS protocol')
.option('--key', 'Path to PEM key for custom SSL certificate')
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/lib/lib/babel-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function(env, options = {}) {
const isProd = env && env.production;
const { production: isProd, rhl: isRHLEnabled } = env || {};

return {
presets: [
Expand Down Expand Up @@ -27,7 +27,7 @@ module.exports = function(env, options = {}) {
[require.resolve('@babel/plugin-transform-react-jsx'), { pragma: 'h' }],
[require.resolve('fast-async'), { spec: true }],
require.resolve('babel-plugin-macros'),
!isProd && require.resolve('react-hot-loader/babel'),
!isProd && isRHLEnabled && require.resolve('react-hot-loader/babel'),
].filter(Boolean),
};
};
8 changes: 5 additions & 3 deletions packages/cli/lib/lib/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ const interopDefault = m => (m && m.default ? m.default : m);
if (process.env.NODE_ENV === 'development') {
// enable preact devtools
require('preact/debug');
// enable hot loader
const hotLoader = interopDefault(require('react-hot-loader'));
hotLoader.preact(interopDefault(require('preact')));
if (process.env.RHL) {
// enable hot loader
const hotLoader = interopDefault(require('react-hot-loader'));
hotLoader.preact(interopDefault(require('preact')));
}
// only add a debug sw if webpack service worker is not requested.
if (!process.env.ADD_SW && 'serviceWorker' in navigator) {
// eslint-disable-next-line no-undef
Expand Down
1 change: 1 addition & 0 deletions packages/cli/lib/lib/webpack/webpack-client-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ function isDev(config) {
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env.ADD_SW': config.sw,
'process.env.RHL': config.rhl,
}),
],

Expand Down

0 comments on commit b8ac82b

Please sign in to comment.