Created
June 3, 2018 18:33
-
-
Save Shine-neko/06bba76d77e8806085616a0e6165dc59 to your computer and use it in GitHub Desktop.
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
const webpack = require('webpack'); | |
const path = require('path'); | |
let root = path.resolve(__dirname); | |
module.exports = { | |
mode: 'development', | |
devServer: { | |
disableHostCheck: true, | |
host: 'localhost', | |
port: 4001, | |
https: false, | |
historyApiFallback: true, | |
hot: true, | |
inline: true, | |
compress: true, | |
}, | |
entry: [ | |
'babel-polyfill', | |
'react-hot-loader/patch', | |
'webpack/hot/only-dev-server', | |
path.join(process.cwd(), 'src/index.js') | |
], | |
output: { | |
path: path.resolve(__dirname, './public'), | |
filename: 'bundle.js' | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.(woff2?|svg)$/, | |
loader: 'url-loader?limit=10000' | |
}, | |
{ | |
test: /\.(ttf|eot)$/, | |
loader: 'file-loader' | |
}, | |
{ | |
test: /\.css$/, | |
loaders: ['style-loader', 'css-loader'] | |
}, | |
{ | |
test: /\.scss$/, | |
loaders: ['style-loader', 'css-loader', 'sass-loader'] | |
}, | |
{ | |
test: /.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/, | |
loader: 'file-loader?name=[hash].[ext]' | |
}, | |
{ | |
test: /\.(js|jsx)$/, | |
loader: require.resolve('babel-loader'), | |
options: { | |
cacheDirectory: true, | |
plugins: ['react-hot-loader/babel'], | |
}, | |
exclude: /(node_modules)/, | |
include: root | |
} | |
] | |
}, | |
cache: true, | |
devtool: 'cheap-module-eval-source-map', | |
plugins:[ | |
new webpack.HotModuleReplacementPlugin() | |
] | |
}; |
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
import ReactDOM from 'react-dom'; | |
import React from 'react'; | |
import { AppContainer } from 'react-hot-loader'; | |
import App from './app'; | |
const render = Component => { | |
ReactDOM.render( | |
<AppContainer> | |
<Component /> | |
</AppContainer>, | |
document.getElementById('app'), | |
) | |
} | |
render(App); | |
if (module.hot) { | |
module.hot.accept('./app.js', () => { | |
const NextRootContainer = require('./app.js').default; | |
render(<NextRootContainer />, document.getElementById('react-root')); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment