-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwebpack.config.client.js
More file actions
executable file
·195 lines (175 loc) · 4.53 KB
/
webpack.config.client.js
File metadata and controls
executable file
·195 lines (175 loc) · 4.53 KB
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
/**
* webpack config for client files
*/
const fs = require('fs');
const path = require('path');
const process = require('process');
const webpack = require('webpack');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
/*
* make sure we build in root dir
*/
process.chdir(__dirname);
module.exports = ({
development,
analyze,
locale = 'en',
extract,
clean = true,
readonly,
}) => {
const ttag = {
resolve: {
translations: (locale !== 'en')
? path.resolve('i18n', `${locale}.po`)
: 'default',
},
};
if (extract) {
ttag.extract = {
output: path.resolve('i18n', 'template.pot'),
};
}
const babelPlugins = [
['ttag', ttag],
];
return {
name: 'client',
target: 'web',
mode: (development) ? 'development' : 'production',
devtool: (development) ? 'source-map' : false,
entry: {
client:
[path.resolve('src', 'client.js')],
globe:
[path.resolve('src', 'globe.js')],
popup:
[path.resolve('src', 'popup.js')],
},
output: {
path: path.resolve('dist', 'public', 'assets'),
publicPath: '/assets/',
// chunkReason is set if it is a split chunk like vendor or three
filename: (pathData) => (pathData.chunk.chunkReason)
? '[name].[chunkhash:8].js'
: `[name].${locale}.[chunkhash:8].js`,
chunkFilename: `[name].${locale}.[chunkhash:8].js`,
clean,
},
resolve: {
alias: {
/*
* have to mock it, because we don't ship ttag itself with the client,
* we have a script for every language
*/
ttag: 'ttag/dist/mock',
/*
* if we don't do that,we might load different versions of three
*/
three: path.resolve('node_modules', 'three'),
},
extensions: ['.js', '.jsx'],
},
module: {
rules: [
{
test: /\.svg$/,
use: [
'babel-loader',
{
loader: 'react-svg-loader',
options: {
svgo: {
plugins: [
{
removeViewBox: false,
},
{
removeDimensions: true,
},
],
},
jsx: false,
},
},
],
},
{
test: /\.(js|jsx)$/,
use: [
{
loader: 'babel-loader',
options: {
plugins: babelPlugins,
},
},
path.resolve('scripts/TtagNonCacheableLoader.js'),
],
include: [
path.resolve('src'),
...['image-q'].map((moduleName) => (
path.resolve('node_modules', moduleName)
)),
],
},
],
},
plugins: [
// Define free variables
// https://webpack.github.io/docs/list-of-plugins.html#defineplugin
new webpack.DefinePlugin({
'process.env.NODE_ENV': development ? '"development"' : '"production"',
'process.env.BROWSER': true,
}),
// Webpack Bundle Analyzer
// https://github.com/th0r/webpack-bundle-analyzer
...analyze ? [new BundleAnalyzerPlugin({ analyzerPort: 8889 })] : [],
],
optimization: {
splitChunks: {
chunks: 'all',
name: false,
cacheGroups: {
default: false,
defaultVendors: false,
/*
* this layout of chunks is also assumed in src/core/assets.js
* client -> client.js + vendor.js
* globe -> globe.js + three.js
*/
vendor: {
name: 'vendor',
chunks: (chunk) => chunk.name.startsWith('client'),
test: /[\\/]node_modules[\\/]/,
},
three: {
name: 'three',
chunks: 'all',
test: /[\\/]node_modules[\\/]three[\\/]/,
},
},
},
},
recordsPath: path.resolve('records.json'),
stats: {
colors: true,
reasons: false,
hash: false,
version: false,
chunkModules: false,
},
cache: {
type: 'filesystem',
readonly,
},
};
}
function getAllAvailableLocals() {
const langDir = path.resolve('i18n');
const langs = fs.readdirSync(langDir)
.filter((e) => (e.endsWith('.po') && !e.startsWith('ssr')))
.map((l) => l.slice(0, -3));
langs.unshift('en');
return langs;
}
module.exports.getAllAvailableLocals = getAllAvailableLocals;