forked from shakacode/react-webpack-rails-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-rails-hot.js
52 lines (42 loc) · 1.38 KB
/
server-rails-hot.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
/* eslint no-var: 0, no-console: 0, import/no-extraneous-dependencies: 0 */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const webpackConfig = require('./webpack.client.rails.hot.config');
const { resolve } = require('path');
const webpackConfigLoader = require('react-on-rails/webpackConfigLoader');
const configPath = resolve('..', 'config');
const { output, settings } = webpackConfigLoader(configPath);
const hotReloadingUrl = output.publicPathWithHost;
const hotReloadingPort = settings.dev_server.port;
const hotReloadingHostname = settings.dev_server.host;
const compiler = webpack(webpackConfig);
const devServer = new WebpackDevServer(compiler, {
proxy: { '*': `http://${hotReloadingHostname}:${hotReloadingPort}` },
publicPath: output.publicPathWithHost,
headers: {
'Access-Control-Allow-Origin': '*',
},
disableHostCheck: true,
hot: true,
inline: true,
historyApiFallback: true,
quiet: false,
noInfo: false,
lazy: false,
stats: {
colors: true,
hash: false,
version: false,
chunks: false,
children: false,
},
});
devServer.listen(hotReloadingPort, hotReloadingHostname, err => {
if (err) console.error(err);
console.log(
`=> 🔥 Webpack development server is running on port ${hotReloadingUrl}`,
);
});
compiler.plugin('done', () => {
process.stdout.write('Webpack: Done!');
});