forked from tbolis/react-back2top
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.server.js
83 lines (76 loc) · 2.45 KB
/
webpack.server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*global __dirname*/
/*eslint no-console:0 */
const path = require('path');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const NoEmitOnErrorsPlugin = require('webpack/lib/NoEmitOnErrorsPlugin');
const HotModuleReplacementPlugin = require('webpack/lib/HotModuleReplacementPlugin');
const srcPath = path.join(__dirname, 'src');
const examplesPath = path.join(__dirname, 'examples');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const port = 23000;
const config = {
entry: {
examples: [
'webpack-dev-server/client?http://localhost:' + port,
'webpack/hot/only-dev-server',
path.join(examplesPath, 'run')
]
},
output: {
path: path.join(__dirname, '/build'),
filename: 'index.js',
publicPath: '/'
},
resolve: {
extensions: ['.js', '.jsx'],
alias: {
'react-back2top': path.join(__dirname, '/src')
}
},
cache: true,
devtool: 'sourcemap',
devServer: {
historyApiFallback: true,
stats: {colors: true},
publicPath: '/',
noInfo: false,
port: port,
hot: true
},
module: {
rules: [
{test: /\.html$/, loader: 'html-loader', include: [examplesPath], exclude: /base\.html$/},
{test: /\.css$/, loader: 'style-loader!css-loader'},
{
test: /\.(js|jsx)$/,
include: [srcPath, examplesPath],
exclude: /(node_modules|bower_components)/,
loaders: ['babel-loader']
}
]
},
plugins: [
new HotModuleReplacementPlugin(),
new NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
title: 'React-Back2Top Button',
description: 'React based back to top button',
keywords: ['React', 'back', 'top', 'scroll-up'],
template: path.join(examplesPath, 'base.html'),
inject: 'body',
filename: 'index.html',
chunks: ['examples']
}),
new OpenBrowserPlugin({url: 'http://localhost:' + port})
]
};
new WebpackDevServer(webpack(config), config.devServer)
.listen(port, 'localhost', function (err) {
if (err) {
console.log(err);
}
console.log('Serving from http://localhost:' + port);
}
);