forked from shakacode/react-webpack-rails-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.client.base.config.js
141 lines (124 loc) · 3.41 KB
/
webpack.client.base.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* eslint comma-dangle: ["error",
{"functions": "never", "arrays": "only-multiline", "objects": "only-multiline"} ] */
// Common client-side webpack configuration used by webpack.hot.config and webpack.rails.config.
const webpack = require('webpack');
const path = require('path');
const devBuild = process.env.NODE_ENV !== 'production';
const nodeEnv = devBuild ? 'development' : 'production';
module.exports = {
// the project dir
context: __dirname,
entry: {
// See use of 'vendor' in the CommonsChunkPlugin inclusion below.
vendor: [
'babel-polyfill',
'es5-shim/es5-shim',
'es5-shim/es5-sham',
'jquery',
'turbolinks',
// Below libraries are listed as entry points to be sure they get included in the
// vendor-bundle.js. Note, if we added some library here, but don't use it in the
// app-bundle.js, then we just wasted a bunch of space.
'axios',
'actioncable',
'classnames',
'immutable',
'lodash',
'marked',
'react-bootstrap',
'react-dom',
'react-redux',
'react-on-rails',
'react-router-redux',
'redux-thunk',
'react-intl',
],
// This will contain the app entry points defined by webpack.hot.config and webpack.rails.config
app: [
'./app/bundles/comments/startup/clientRegistration',
],
},
resolve: {
extensions: ['.js', '.jsx'],
alias: {
libs: path.resolve(__dirname, 'app/libs'),
react: path.resolve(__dirname, 'node_modules/react'),
'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
},
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(nodeEnv),
},
TRACE_TURBOLINKS: devBuild,
}),
// https://webpack.github.io/docs/list-of-plugins.html#2-explicit-vendor-chunk
new webpack.optimize.CommonsChunkPlugin({
// This name 'vendor' ties into the entry definition
name: 'vendor',
// We don't want the default vendor.js name
filename: 'vendor-bundle.js',
// Passing Infinity just creates the commons chunk, but moves no modules into it.
// In other words, we only put what's in the vendor entry definition in vendor-bundle.js
minChunks: Infinity,
}),
],
module: {
rules: [
{
test: /\.(ttf|eot)$/,
use: 'file-loader',
},
{
test: /\.(woff2?|jpe?g|png|gif|svg|ico)$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
},
},
},
{
test: require.resolve('jquery'),
use: [
{
loader: 'expose-loader',
query: 'jQuery'
},
{
loader: 'expose-loader',
query: '$'
}
]
},
{
test: require.resolve('turbolinks'),
use: {
loader: 'imports-loader?this=>window'
},
},
// Use one of these to serve jQuery for Bootstrap scripts:
// Bootstrap 3
{
test: /bootstrap-sass\/assets\/javascripts\//,
use: {
loader: 'imports-loader',
options: {
jQuery: 'jquery',
},
},
},
// Bootstrap 4
{
test: /bootstrap\/dist\/js\/umd\//,
use: {
loader: 'imports-loader',
options: {
jQuery: 'jquery',
},
},
},
],
},
};