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
123 lines (111 loc) · 2.59 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* 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 path = require('path');
const webpack = require('webpack');
const config = require('./webpack.client.base.config');
const hotRailsPort = process.env.HOT_RAILS_PORT || 3500;
config.entry.app.push(
`webpack-dev-server/client?http://localhost:${hotRailsPort}`,
'webpack/hot/only-dev-server'
);
// These are Rails specific
config.entry.vendor.push(
'jquery-ujs',
'bootstrap-loader'
);
config.output = {
filename: '[name]-bundle.js',
path: path.join(__dirname, 'public'),
publicPath: `http://localhost:${hotRailsPort}/`,
};
config.module.rules.push(
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
plugins: [
[
'react-transform',
{
superClasses: ['React.Component', 'BaseComponent', 'Component'],
transforms: [
{
transform: 'react-transform-hmr',
imports: ['react'],
locals: ['module'],
},
],
},
],
],
},
},
{
test: /\.css$/,
use: [
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 0,
localIdentName: '[name]__[local]__[hash:base64:5]'
}
},
{
loader: 'postcss-loader',
options: {
plugins: 'autoprefixer'
}
}
]
},
{
test: /\.scss$/,
use: [
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 3,
localIdentName: '[name]__[local]__[hash:base64:5]',
}
},
{
loader: 'postcss-loader',
options: {
plugins: 'autoprefixer'
}
},
{
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',
}
}
}
);
config.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
);
config.devtool = 'eval-source-map';
console.log('Webpack dev build for Rails'); // eslint-disable-line no-console
module.exports = config;