forked from shakacode/react-webpack-rails-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.client.rails.hot.config.js
106 lines (96 loc) · 2.54 KB
/
webpack.client.rails.hot.config.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* eslint comma-dangle: ["error",
{"functions": "never", "arrays": "only-multiline", "objects": "only-multiline"} ] */
// Run with Rails server like this:
// rails s
// cd client && babel-node server-rails-hot.js
// Note that Foreman (Procfile.dev) has also been configured to take care of this.
const webpack = require('webpack');
const merge = require('webpack-merge');
const { resolve } = require('path');
const config = require('./webpack.client.base.config');
const webpackConfigLoader = require('react-on-rails/webpackConfigLoader');
const configPath = resolve('..', 'config');
const { output } = webpackConfigLoader(configPath);
const hotReloadingUrl = output.publicPathWithHost;
module.exports = merge(config, {
devtool: 'eval-source-map',
entry: {
'app-bundle': [
`webpack-dev-server/client?${hotReloadingUrl}`,
'webpack/hot/only-dev-server'
],
// These are Rails specific
'vendor-bundle': [
'jquery-ujs',
'bootstrap-loader'
],
},
output: {
filename: '[name]-[hash].js',
chunkFilename: '[name]-[chunkhash].chunk.js',
publicPath: output.publicPath,
path: output.path,
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 0,
localIdentName: '[name]__[local]__[hash:base64:5]'
}
},
'postcss-loader',
]
},
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 3,
localIdentName: '[name]__[local]__[hash:base64:5]',
}
},
'postcss-loader',
{
loader: 'sass-loader'
},
{
loader: 'sass-resources-loader',
options: {
resources: './app/assets/styles/app-variables.scss'
},
}
],
},
{
test: require.resolve('jquery-ujs'),
use: {
loader: 'imports-loader',
options: {
jQuery: 'jquery',
}
}
},
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
],
});
console.log('Webpack HOT dev build for Rails'); // eslint-disable-line no-console