forked from metabrainz/bookbrainz-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.client.js
199 lines (189 loc) · 4.73 KB
/
webpack.client.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* eslint import/no-commonjs: 0,
import/unambiguous: 0,
import/no-commonjs: 0
*/
const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WriteAssetsWebpackPlugin = require('write-assets-webpack-plugin');
const production = process.env.NODE_ENV === 'production';
let config = {
context: path.resolve(__dirname, 'src', 'client'),
entry: {
deletion: ['./controllers/deletion.js'],
index: ['./controllers/index.js'],
registrationDetails: ['./controllers/registrationDetails.js'],
revision: ['./controllers/revision.js'],
search: ['./controllers/search.js'],
statistics: ['./controllers/statistics.js'],
'editor/achievement': ['./controllers/editor/achievement.js'],
'editor/edit': ['./controllers/editor/edit.js'],
'editor/editor': ['./controllers/editor/editor.js'],
'entity/entity': ['./controllers/entity/entity.js'],
'entity-editor': ['./entity-editor/controller.js']
},
output: {
chunkFilename: production ? 'js/[name].[chunkhash].js' : 'js/[name].js',
filename: production ? 'js/[name].[chunkhash].js' : 'js/[name].js',
path: path.resolve(__dirname, 'static'),
publicPath: '/static'
},
mode: production ? 'production' : 'development',
module: {
rules: [
{
enforce: 'pre',
exclude: /node_modules/,
test: /\.(js|jsx)$/,
use: {
loader: 'eslint-loader',
options: {
cache: !production,
fix: !production
}
}
},
{
exclude: /node_modules/,
test: /\.(js|jsx)$/,
use: {
loader: 'babel-loader',
options: {
presets: [
'flow',
'react',
['env', {
targets: {
node: 'current'
}
}]
],
plugins: ['react-hot-loader/babel']
}
}
},
{
test: /\.(le|c)ss$/,
use: [
{
loader: !production ? 'style-loader' : MiniCssExtractPlugin.loader
},
{
loader: 'css-loader',
options: {
importLoaders: 1,
sourceMap: !production
}
},
'resolve-url-loader',
{
loader: 'less-loader',
options: {
paths: [path.resolve(__dirname, 'node_modules', 'bootstrap', 'less')],
sourceMap: !production
}
}
]
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'webfonts/',
paths: [
path.resolve(__dirname, 'node_modules', '@fontwasome', 'fontwasome-free')
]
}
}]
},
{
test: /\.(jpg|jpeg|png|gif|svg)$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'images/',
paths: [
path.resolve(__dirname, 'src', 'stylesheets')
]
}
}]
}
]
},
optimization: {
minimize: production,
splitChunks: {
cacheGroups: {
commons: {
chunks: 'all',
name: 'bundle',
test: /[\\/]node_modules[\\/]/
}
// Haven't figured out production less compilation yet
// ,
// styles: {
// chunks: 'all',
// enforce: true,
// name: 'style',
// test: /\.(le|c)ss$/
// }
}
}
},
plugins:[
new MiniCssExtractPlugin({
// chunkFilename: 'stylesheets/[id].css',
// filename: 'stylesheets/style.css'
filename: 'stylesheets/[name].css'
}),
new CleanWebpackPlugin(
[
'static/js',
// Clean up hot-update files that are created by react-hot-loader and written to disk by WriteAssetsWebpackPlugin
// Working on a way for WriteAssetsWebpackPlugin to ignore .hot-update.js files but no luck so far.
'static/**/*.hot-update.js',
'static/editor',
'static/entity'
/* , 'static/stylesheets' */
],
{exclude:[".keep"]}
),
// Because of server-side rendering and the absence of a static html file we could modify with HtmlWebpackPlugin,
// we need the js files to exist on disk
new WriteAssetsWebpackPlugin({
extension: ['js', 'css'],
force: true
})
]
}
if (production) {
// Haven't figured out production less compilation yet
/* config.optimization.splitChunks.cacheGroups.styles = {
chunks: 'all',
enforce: true,
name: 'style',
test: /\.(le|c)ss$/
}; */
}
else {
config.plugins = [
...config.plugins,
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin()
]
if (process.env.BUNDLE_ANALYZER) {
config.plugins.push(new BundleAnalyzerPlugin());
}
for (const entry in config.entry) {
if (Object.prototype.hasOwnProperty.call(config.entry, entry)) {
config.entry[entry].push('webpack-hot-middleware/client');
}
}
config.devtool = 'inline-source-map';
}
module.exports = config;