forked from metabrainz/bookbrainz-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.client.js
169 lines (160 loc) · 4.69 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
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 CompressionPlugin = require('compression-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const production = process.env.NODE_ENV === 'production';
const clientConfig = {
context: path.resolve(__dirname, 'src', 'client'),
entry: {
collection: ['./controllers/collection/collection'],
'collection/create': ['./controllers/collection/userCollectionForm'],
collections: ['./controllers/collections'],
deletion: ['./controllers/deletion.js'],
error: ['./controllers/error.js'],
index: ['./controllers/index.js'],
registrationDetails: ['./controllers/registrationDetails.js'],
revision: ['./controllers/revision.js'],
revisions: ['./controllers/revisions.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'],
'entity-merge': ['./entity-editor/entity-merge.tsx'],
style: './stylesheets/style.less'
},
output: {
/** Figure out how to use manifest to load the right chunkNamed file in src/server/templates/target.js */
// chunkFilename: production ? 'js/[name].[chunkhash].js' : 'js/[name].js',
// filename: production ? 'js/[name].[chunkhash].js' : 'js/[name].js',
filename: 'js/[name].js',
path: path.resolve(__dirname, 'static'),
publicPath: '/static/',
hotUpdateChunkFilename: 'hot/[id].[hash].hot-update.js',
hotUpdateMainFilename: 'hot/[hash].hot-update.json'
},
mode: production ? 'production' : 'development',
module: {
rules: [
{
// babel configuration in .babelrc file
exclude: /node_modules/,
test: /\.(js|jsx|ts|tsx)$/,
use: ['babel-loader']
},
{
test: /\.(le|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 2,
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: {
emitFile: false,
name: '[name].[ext]',
outputPath: 'webfonts/',
}
}]
},
{
test: /\.(jpg|jpeg|png|gif|svg)$/,
use: [{
loader: 'file-loader',
options: {
emitFile: false,
name: '[name].[ext]',
outputPath: 'images/',
}
}]
}
]
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
chunks: 'all',
name: 'bundle',
test: /[\\/]node_modules[\\/]/
}
}
}
},
plugins:[
new MiniCssExtractPlugin({
// chunkFilename: 'stylesheets/[id].css',
filename: 'stylesheets/style.css'
}),
new CleanWebpackPlugin(
[
'static/js',
'static/stylesheets',
// 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'
],
{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
}),
new ESLintPlugin({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
fix: !production
})
],
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
target: 'web'
}
if (production) {
clientConfig.plugins.push(new CompressionPlugin());
}
if (!production) {
clientConfig.plugins = [
...clientConfig.plugins,
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin()
]
if (process.env.BUNDLE_ANALYZER) {
clientConfig.plugins.push(new BundleAnalyzerPlugin());
}
/* Add webpack HMR middleware to all entry files except for styles */
for (const entry in clientConfig.entry) {
if (Object.prototype.hasOwnProperty.call(clientConfig.entry, entry)) {
if(entry !== "style"){
clientConfig.entry[entry].push('webpack-hot-middleware/client');
}
}
}
clientConfig.devtool = 'inline-source-map';
}
module.exports = clientConfig;