forked from tbolis/react-sketch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.server.js
85 lines (79 loc) · 2.63 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
84
85
/*global __dirname*/
/*eslint no-console:0 */
const path = require('path');
const webpack = require('webpack');
const myLocalIP = require('my-local-ip');
const WebpackDevServer = require('webpack-dev-server');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin');
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 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']
},
devtool: 'inline-source-map',
devServer: {
historyApiFallback: true,
stats: {colors: true},
publicPath: '/',
noInfo: false,
lazy: false,
port: port,
hot: true
},
module: {
loaders: [
{test: /\.css$/, loader: 'style-loader!css-loader'},
{
test: /\.(js|jsx)$/,
include: [srcPath, examplesPath],
exclude: /(node_modules|bower_components|lib)/,
loaders: ['babel-loader']
}
]
},
plugins: [
new HotModuleReplacementPlugin(),
new NamedModulesPlugin(),
new NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
title: 'React Sketch',
description: 'Sketch Element for React based applications, backed-up by fabricjs as its core',
keywords: ['react', 'canvas', 'sketch', 'fabricjs', 'fabric.js'],
template: path.join(examplesPath, 'base.html'),
inject: 'body',
filename: 'index.html',
chunks: ['examples']
}),
new DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('development')
}
}),
new OpenBrowserPlugin({url: 'http://localhost:' + port})
]
};
new WebpackDevServer(webpack(config), config.devServer)
.listen(port, '0.0.0.0', function (err) {
err && console.log(err);
console.log('Serving from http://' + myLocalIP() + ':' + port);
}
);