Skip to content

chore(hmr): add initial hot-module-replacement example #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/hot-module-replacement/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "hot-module-replacement",
"version": "0.1.0",
"description": "A simple demonstration of webpack's Hot Module Replacement feature",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server"
},
"author": "Greg Venech",
"license": "ISC",
"devDependencies": {
"html-webpack-plugin": "^2.29.0",
"webpack": "^3.3.0",
"webpack-dev-server": "^2.5.1"
}
}
10 changes: 10 additions & 0 deletions examples/hot-module-replacement/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Library from './library';

Library.log();

if (module.hot) {
module.hot.accept('./library', function() {
console.log('Accepting the updated library module!');
Library.log();
});
}
6 changes: 6 additions & 0 deletions examples/hot-module-replacement/src/library.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
log() {
// Change this after the server is started to test
console.log('First log...');
}
};
24 changes: 24 additions & 0 deletions examples/hot-module-replacement/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: './src/index.js',
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
title: 'Hot Module Replacement'
})
],
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, './dist'),
publicPath: '/'
},
devServer: {
hot: true,
port: 8081,
contentBase: path.resolve(__dirname, './dist'),
}
};