2020-12-01 12:11:48 +00:00
|
|
|
/**
|
2022-08-16 00:43:48 +00:00
|
|
|
* webpack config for client files
|
2020-12-01 12:11:48 +00:00
|
|
|
*/
|
|
|
|
|
2022-08-16 00:43:48 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const process = require('process');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
|
|
|
|
2022-09-18 00:23:43 +00:00
|
|
|
/*
|
|
|
|
* make sure we build in root dir
|
|
|
|
*/
|
2022-08-16 00:43:48 +00:00
|
|
|
process.chdir(__dirname);
|
2020-12-01 12:11:48 +00:00
|
|
|
|
2023-12-12 21:17:57 +00:00
|
|
|
module.exports = ({
|
2021-02-01 19:16:01 +00:00
|
|
|
development,
|
|
|
|
analyze,
|
2023-12-12 21:17:57 +00:00
|
|
|
locale = 'en',
|
2021-02-01 19:16:01 +00:00
|
|
|
extract,
|
2023-12-12 21:17:57 +00:00
|
|
|
clean = true,
|
|
|
|
readonly,
|
|
|
|
}) => {
|
2021-01-29 01:15:33 +00:00
|
|
|
const ttag = {
|
|
|
|
resolve: {
|
2023-12-12 16:58:59 +00:00
|
|
|
translations: (locale !== 'en')
|
2022-08-16 00:43:48 +00:00
|
|
|
? path.resolve('i18n', `${locale}.po`)
|
2023-12-12 16:58:59 +00:00
|
|
|
: 'default',
|
2021-01-29 01:15:33 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-02-01 19:16:01 +00:00
|
|
|
if (extract) {
|
2021-02-01 04:00:47 +00:00
|
|
|
ttag.extract = {
|
2022-08-16 00:43:48 +00:00
|
|
|
output: path.resolve('i18n', 'template.pot'),
|
2021-02-01 19:16:01 +00:00
|
|
|
};
|
2021-02-01 04:00:47 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 01:15:33 +00:00
|
|
|
const babelPlugins = [
|
|
|
|
['ttag', ttag],
|
|
|
|
];
|
|
|
|
|
|
|
|
return {
|
|
|
|
name: 'client',
|
|
|
|
target: 'web',
|
|
|
|
|
|
|
|
mode: (development) ? 'development' : 'production',
|
2023-12-12 21:17:57 +00:00
|
|
|
devtool: (development) ? 'source-map' : false,
|
2021-01-29 01:15:33 +00:00
|
|
|
|
|
|
|
entry: {
|
2023-12-11 21:11:55 +00:00
|
|
|
client:
|
2022-08-16 00:43:48 +00:00
|
|
|
[path.resolve('src', 'client.js')],
|
2023-12-11 21:11:55 +00:00
|
|
|
globe:
|
2022-08-16 00:43:48 +00:00
|
|
|
[path.resolve('src', 'globe.js')],
|
2023-12-11 21:11:55 +00:00
|
|
|
popup:
|
2022-09-03 23:17:59 +00:00
|
|
|
[path.resolve('src', 'popup.js')],
|
2021-01-29 01:15:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
output: {
|
2022-08-16 00:43:48 +00:00
|
|
|
path: path.resolve('dist', 'public', 'assets'),
|
2023-12-11 19:54:52 +00:00
|
|
|
publicPath: '/assets/',
|
2023-12-11 21:11:55 +00:00
|
|
|
// 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`,
|
2023-12-11 19:54:52 +00:00
|
|
|
chunkFilename: `[name].${locale}.[chunkhash:8].js`,
|
2023-12-12 17:58:53 +00:00
|
|
|
clean,
|
2021-01-29 01:15:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
2022-07-11 19:47:52 +00:00
|
|
|
/*
|
|
|
|
* have to mock it, because we don't ship ttag itself with the client,
|
|
|
|
* we have a script for every language
|
|
|
|
*/
|
2021-01-29 01:15:33 +00:00
|
|
|
ttag: 'ttag/dist/mock',
|
2022-07-11 19:47:52 +00:00
|
|
|
/*
|
|
|
|
* if we don't do that,we might load different versions of three
|
|
|
|
*/
|
2022-08-16 00:43:48 +00:00
|
|
|
three: path.resolve('node_modules', 'three'),
|
2021-01-29 01:15:33 +00:00
|
|
|
},
|
2022-01-02 20:50:42 +00:00
|
|
|
extensions: ['.js', '.jsx'],
|
2021-01-29 01:15:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.svg$/,
|
|
|
|
use: [
|
2023-12-12 15:29:16 +00:00
|
|
|
'babel-loader',
|
2021-01-29 01:15:33 +00:00
|
|
|
{
|
|
|
|
loader: 'react-svg-loader',
|
|
|
|
options: {
|
|
|
|
svgo: {
|
|
|
|
plugins: [
|
|
|
|
{
|
|
|
|
removeViewBox: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
removeDimensions: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
jsx: false,
|
2020-12-01 12:11:48 +00:00
|
|
|
},
|
|
|
|
},
|
2021-01-29 01:15:33 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2022-01-01 00:39:01 +00:00
|
|
|
test: /\.(js|jsx)$/,
|
2023-12-12 15:29:16 +00:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
plugins: babelPlugins,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
path.resolve('scripts/TtagNonCacheableLoader.js'),
|
|
|
|
],
|
2021-01-29 01:15:33 +00:00
|
|
|
include: [
|
2022-08-16 00:43:48 +00:00
|
|
|
path.resolve('src'),
|
2022-01-02 20:50:42 +00:00
|
|
|
...['image-q'].map((moduleName) => (
|
2022-08-16 14:32:59 +00:00
|
|
|
path.resolve('node_modules', moduleName)
|
|
|
|
)),
|
2021-01-29 01:15:33 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
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 })] : [],
|
2020-12-01 12:11:48 +00:00
|
|
|
],
|
2021-01-29 01:15:33 +00:00
|
|
|
|
|
|
|
optimization: {
|
|
|
|
splitChunks: {
|
|
|
|
chunks: 'all',
|
|
|
|
name: false,
|
|
|
|
cacheGroups: {
|
|
|
|
default: false,
|
|
|
|
defaultVendors: false,
|
|
|
|
|
2023-12-11 15:46:23 +00:00
|
|
|
/*
|
|
|
|
* this layout of chunks is also assumed in src/core/assets.js
|
|
|
|
* client -> client.js + vendor.js
|
|
|
|
* globe -> globe.js + three.js
|
|
|
|
*/
|
2021-01-29 01:15:33 +00:00
|
|
|
vendor: {
|
|
|
|
name: 'vendor',
|
|
|
|
chunks: (chunk) => chunk.name.startsWith('client'),
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
},
|
|
|
|
three: {
|
|
|
|
name: 'three',
|
|
|
|
chunks: 'all',
|
|
|
|
test: /[\\/]node_modules[\\/]three[\\/]/,
|
|
|
|
},
|
2020-12-02 22:22:59 +00:00
|
|
|
},
|
2020-12-01 12:11:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-12-12 15:29:16 +00:00
|
|
|
recordsPath: path.resolve('records.json'),
|
2023-12-11 19:54:52 +00:00
|
|
|
|
2021-01-29 21:46:58 +00:00
|
|
|
stats: {
|
|
|
|
colors: true,
|
|
|
|
reasons: false,
|
|
|
|
hash: false,
|
|
|
|
version: false,
|
|
|
|
chunkModules: false,
|
|
|
|
},
|
|
|
|
|
2023-12-12 17:58:53 +00:00
|
|
|
cache: {
|
2023-12-12 21:17:57 +00:00
|
|
|
type: 'filesystem',
|
|
|
|
readonly,
|
|
|
|
},
|
2021-01-29 01:15:33 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|