-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from blainekasten/support-whm
Support webpack-hot-middleware
- Loading branch information
Showing
21 changed files
with
5,148 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = api => { | ||
// This caches the Babel config | ||
api.cache.using(() => process.env.NODE_ENV); | ||
return { | ||
presets: ['@babel/preset-env', '@babel/preset-react'], | ||
// Applies the react-refresh Babel plugin on non-production modes only | ||
...(!api.env('production') && { plugins: ['react-refresh/babel'] }), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "whm-kitchen-sink", | ||
"version": "0.1.0", | ||
"main": "index.js", | ||
"author": "Michael Mok", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "node ./server", | ||
"build": "cross-env NODE_ENV=production webpack --mode production" | ||
}, | ||
"dependencies": { | ||
"react": "^16.9.0", | ||
"react-dom": "^16.9.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.6.0", | ||
"@babel/preset-env": "^7.6.0", | ||
"@babel/preset-react": "^7.0.0", | ||
"babel-loader": "^8.0.6", | ||
"cross-env": "^6.0.3", | ||
"express": "^4.17.1", | ||
"html-webpack-plugin": "^3.2.0", | ||
"react-refresh": "^0.7.0", | ||
"@pmmmwh/react-refresh-webpack-plugin": "^0.1.1", | ||
"webpack": "^4.41.2", | ||
"webpack-dev-middleware": "^3.7.2", | ||
"webpack-hot-middleware": "^2.25.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>WHM React App</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const express = require('express'); | ||
const webpack = require('webpack'); | ||
const path = require('path'); | ||
const config = require('./webpack.config.js'); | ||
const compiler = webpack(config); | ||
|
||
const app = express(); | ||
|
||
app.use( | ||
require('webpack-dev-middleware')(compiler, { | ||
publicPath: config.output.publicPath, | ||
}) | ||
); | ||
|
||
app.use( | ||
require(`webpack-hot-middleware`)(compiler, { | ||
log: false, | ||
path: `/__webpack_hmr`, | ||
heartbeat: 10 * 1000, | ||
}) | ||
); | ||
|
||
app.listen(3000, () => console.log('App is listening on port 3000!')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as React from 'react'; | ||
import ClassDefault from './ClassDefault'; | ||
import { ClassNamed } from './ClassNamed'; | ||
import FunctionDefault from './FunctionDefault'; | ||
import { FunctionNamed } from './FunctionNamed'; | ||
|
||
const LazyComponent = React.lazy(() => import('./LazyComponent')); | ||
|
||
function App() { | ||
return ( | ||
<div> | ||
<ClassDefault /> | ||
<ClassNamed /> | ||
<FunctionDefault /> | ||
<FunctionNamed /> | ||
<React.Suspense fallback={<h1>Loading</h1>}> | ||
<LazyComponent /> | ||
</React.Suspense> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as React from 'react'; | ||
|
||
class ClassDefault extends React.Component { | ||
render() { | ||
return <h1>Default Export Class</h1>; | ||
} | ||
} | ||
|
||
export default ClassDefault; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as React from 'react'; | ||
|
||
export class ClassNamed extends React.Component { | ||
render() { | ||
return <h1>Named Export Class</h1>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as React from 'react'; | ||
|
||
function FunctionDefault() { | ||
return <h1>Default Export Function</h1>; | ||
} | ||
|
||
export default FunctionDefault; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as React from 'react'; | ||
|
||
export function FunctionNamed() { | ||
return <h1>Named Export Function</h1>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as React from 'react'; | ||
|
||
function LazyComponent() { | ||
return <h1>Lazy Component</h1>; | ||
} | ||
|
||
export default LazyComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as React from 'react'; | ||
import { render } from 'react-dom'; | ||
import App from './App'; | ||
|
||
render(<App />, document.getElementById('app')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const webpack = require('webpack'); | ||
const ReactRefreshPlugin = require('../../src'); | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
entry: { | ||
main: ['webpack-hot-middleware/client', './src/index.js'], | ||
}, | ||
output: { | ||
path: __dirname, | ||
publicPath: '/', | ||
filename: 'bundle.js', | ||
}, | ||
mode: 'development', | ||
target: 'web', | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jsx?$/, | ||
exclude: /node_modules/, | ||
use: 'babel-loader', | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new webpack.HotModuleReplacementPlugin(), | ||
new ReactRefreshPlugin(), | ||
new HtmlWebpackPlugin({ | ||
template: './public/index.html', | ||
filename: './index.html', | ||
}), | ||
new webpack.NoEmitOnErrorsPlugin(), | ||
], | ||
resolve: { | ||
extensions: ['.js', '.jsx'], | ||
}, | ||
}; |
Oops, something went wrong.