Skip to content

Instantly share code, notes, and snippets.

@markmur
Created April 19, 2016 13:05
Show Gist options
  • Save markmur/02cbccb44277ac34b8da4f3e448a95ac to your computer and use it in GitHub Desktop.
Save markmur/02cbccb44277ac34b8da4f3e448a95ac to your computer and use it in GitHub Desktop.
Webpack Hot Reload
'use strict';
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: [
'babel-polyfill',
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/dev-server',
'./assets/main.jsx',
],
output: {
path: path.join(__dirname, '/public/dist/'),
filename: 'bundle.js',
pathInfo: true,
publicPath: 'http://localhost:8080/dist/',
hot: true,
},
resolve: {
root: path.join(__dirname, ''),
modulesDirectories: [
'web_modules',
'node_modules',
'assets',
'assets/components',
'assets/styles',
],
extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx'],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
__ENV__: NODE_ENV,
}),
],
module: {
loaders: [
{
test: /\.scss$/, // sass files
loader: 'style!css!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded',
},
{
test: /\.(ttf|eot|svg|woff)(\?[a-z0-9]+)?$/, // fonts files
loader: 'file-loader?name=[path][name].[ext]',
},
{
test: /\.jsx?$/, // react files
exclude: /node_modules/,
loaders: ['react-hot', 'babel?presets[]=es2015,presets[]=stage-0,presets[]=react'],
include: path.join(__dirname, 'assets'),
},
],
noParse: /\.min\.js/,
},
};
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
const PORT = 8080;
const colors = require('colors');
var server = new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
noInfo: true,
historyApiFallback: true
}).listen(PORT, 'localhost', function (err, result) {
if (err) console.log(err);
console.log('===================================='.magenta);
console.log(' WEBPACK DEV SERVER ');
console.log('===================================='.magenta);
console.log('Listening at', `http://localhost:${PORT}`.magenta);
console.log('===================================='.magenta);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment