2020-12-01 12:11:48 +00:00
|
|
|
/*
|
2022-08-16 00:43:48 +00:00
|
|
|
* webpack config to build server 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 nodeExternals = require('webpack-node-externals');
|
|
|
|
const GeneratePackageJsonPlugin = require('generate-package-json-webpack-plugin');
|
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
2020-12-01 12:11:48 +00:00
|
|
|
|
2022-08-16 00:43:48 +00:00
|
|
|
const pkg = require('./package.json');
|
|
|
|
|
|
|
|
// make sure we build in root dir
|
|
|
|
process.chdir(__dirname);
|
2020-12-01 12:11:48 +00:00
|
|
|
|
|
|
|
const basePackageValues = {
|
|
|
|
name: pkg.name,
|
|
|
|
version: pkg.version,
|
|
|
|
private: true,
|
|
|
|
engines: pkg.engines,
|
|
|
|
scripts: {
|
2022-01-03 12:59:40 +00:00
|
|
|
start: 'node --nouse-idle-notification --expose-gc server.js',
|
2020-12-01 12:11:48 +00:00
|
|
|
},
|
|
|
|
dependencies: {
|
2020-12-02 20:20:45 +00:00
|
|
|
mysql2: '',
|
2022-01-11 23:15:40 +00:00
|
|
|
'utf-8-validate': '',
|
|
|
|
bufferutil: '',
|
2020-12-01 12:11:48 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-02-01 19:16:01 +00:00
|
|
|
const ttag = {};
|
2020-12-01 12:11:48 +00:00
|
|
|
const babelPlugins = [
|
2021-02-01 19:16:01 +00:00
|
|
|
['ttag', ttag],
|
2020-12-01 12:11:48 +00:00
|
|
|
];
|
|
|
|
|
2022-08-16 00:43:48 +00:00
|
|
|
module.exports = ({
|
2022-01-01 00:39:01 +00:00
|
|
|
development, extract,
|
2021-02-01 19:16:01 +00:00
|
|
|
}) => {
|
2022-06-20 20:54:05 +00:00
|
|
|
/*
|
|
|
|
* write template files for translations
|
|
|
|
*/
|
2021-02-01 19:16:01 +00:00
|
|
|
if (extract) {
|
|
|
|
ttag.extract = {
|
2022-08-16 00:43:48 +00:00
|
|
|
output: path.resolve('i18n', 'template-ssr.pot'),
|
2021-02-01 19:16:01 +00:00
|
|
|
};
|
|
|
|
ttag.discover = ['t', 'jt'];
|
|
|
|
}
|
2020-12-01 12:11:48 +00:00
|
|
|
|
2022-06-20 20:54:05 +00:00
|
|
|
/*
|
|
|
|
* worker threads need to be their own
|
|
|
|
* entry points
|
|
|
|
*/
|
2022-08-16 00:43:48 +00:00
|
|
|
const workersDir = path.resolve('src', 'workers');
|
2022-06-20 20:54:05 +00:00
|
|
|
const workerEntries = {};
|
|
|
|
fs.readdirSync(workersDir)
|
|
|
|
.filter((e) => e.endsWith('.js'))
|
|
|
|
.forEach((filename) => {
|
|
|
|
const name = `workers/${filename.slice(0, -3)}`;
|
|
|
|
const fullPath = path.resolve(workersDir, filename);
|
|
|
|
workerEntries[name] = fullPath;
|
|
|
|
});
|
|
|
|
|
2021-02-01 19:16:01 +00:00
|
|
|
return {
|
2022-01-03 12:59:40 +00:00
|
|
|
name: 'server',
|
2021-02-01 19:16:01 +00:00
|
|
|
target: 'node',
|
2020-12-01 12:11:48 +00:00
|
|
|
|
2022-01-01 00:39:01 +00:00
|
|
|
mode: (development) ? 'development' : 'production',
|
2020-12-01 12:11:48 +00:00
|
|
|
|
2021-02-01 19:16:01 +00:00
|
|
|
entry: {
|
2022-08-16 00:43:48 +00:00
|
|
|
server: [path.resolve('src', 'server.js')],
|
|
|
|
backup: [path.resolve('src', 'backup.js')],
|
2022-06-20 20:54:05 +00:00
|
|
|
...workerEntries,
|
2021-02-01 19:16:01 +00:00
|
|
|
},
|
2020-12-01 12:11:48 +00:00
|
|
|
|
2021-02-01 19:16:01 +00:00
|
|
|
output: {
|
2021-03-18 16:15:18 +00:00
|
|
|
clean: true,
|
2021-02-01 19:16:01 +00:00
|
|
|
},
|
2020-12-01 12:11:48 +00:00
|
|
|
|
2021-02-01 19:16:01 +00:00
|
|
|
resolve: {
|
2022-01-02 20:50:42 +00:00
|
|
|
extensions: ['.js', '.jsx'],
|
2021-02-01 19:16:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2022-01-02 20:50:42 +00:00
|
|
|
test: /\.(js|jsx)$/,
|
2021-02-01 19:16:01 +00:00
|
|
|
loader: 'babel-loader',
|
2022-08-16 12:40:06 +00:00
|
|
|
include: [
|
|
|
|
path.resolve('src'),
|
|
|
|
],
|
2021-02-01 19:16:01 +00:00
|
|
|
options: {
|
|
|
|
cacheDirectory: false,
|
|
|
|
plugins: babelPlugins,
|
|
|
|
},
|
2020-12-01 12:11:48 +00:00
|
|
|
},
|
2021-02-01 19:16:01 +00:00
|
|
|
{
|
|
|
|
test: /\.css/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 1,
|
|
|
|
sourceMap: false,
|
|
|
|
modules: false,
|
|
|
|
},
|
2020-12-01 12:11:48 +00:00
|
|
|
},
|
2022-01-05 12:25:18 +00:00
|
|
|
'clean-css-loader',
|
2021-02-01 19:16:01 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: [/\.po$/],
|
|
|
|
loader: 'ttag-po-loader',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
2022-08-16 00:43:48 +00:00
|
|
|
externalsPresets: {
|
2022-08-16 14:32:59 +00:00
|
|
|
// exclude built-in node modules (path, fs, etc.)
|
2022-08-16 00:43:48 +00:00
|
|
|
node: true,
|
|
|
|
},
|
|
|
|
|
2021-02-01 19:16:01 +00:00
|
|
|
externals: [
|
2022-08-16 00:43:48 +00:00
|
|
|
nodeExternals({
|
|
|
|
// passport-reddit is an ESM module
|
|
|
|
// bundle it, then we don't have to import it
|
2022-08-16 14:32:59 +00:00
|
|
|
allowlist: [ /^passport-/ ],
|
2022-08-16 00:43:48 +00:00
|
|
|
}),
|
2021-02-01 19:16:01 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
2022-01-01 00:39:01 +00:00
|
|
|
'process.env.NODE_ENV': development ? '"development"' : '"production"',
|
2021-02-01 19:16:01 +00:00
|
|
|
'process.env.BROWSER': false,
|
|
|
|
}),
|
|
|
|
// create package.json for deployment
|
|
|
|
new GeneratePackageJsonPlugin(basePackageValues, {
|
2022-08-16 00:43:48 +00:00
|
|
|
sourcePackageFilenames: [ path.resolve('package.json') ],
|
|
|
|
// provided by node itself
|
|
|
|
excludeDependencies: ['node:buffer'],
|
2021-02-01 19:16:01 +00:00
|
|
|
}),
|
2021-03-18 16:15:18 +00:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
2022-08-16 00:43:48 +00:00
|
|
|
from: path.resolve('public'),
|
|
|
|
to: path.resolve('dist', 'public'),
|
2021-03-18 16:15:18 +00:00
|
|
|
},
|
2022-08-16 00:43:48 +00:00
|
|
|
path.resolve('src', 'canvases.json'),
|
2021-03-18 16:15:18 +00:00
|
|
|
{
|
2022-08-16 00:43:48 +00:00
|
|
|
from: path.resolve('deployment', 'example-ecosystem.yml'),
|
|
|
|
to: path.resolve('dist', 'ecosystem.yml'),
|
2021-03-18 16:15:18 +00:00
|
|
|
},
|
|
|
|
{
|
2022-08-16 00:43:48 +00:00
|
|
|
from: path.resolve('deployment', 'example-ecosystem-backup.yml'),
|
|
|
|
to: path.resolve('dist', 'ecosystem-backup.yml'),
|
2021-03-18 16:15:18 +00:00
|
|
|
},
|
2021-08-21 15:08:28 +00:00
|
|
|
{
|
2022-08-16 00:43:48 +00:00
|
|
|
from: path.resolve('deployment', 'captchaFonts'),
|
|
|
|
to: path.resolve('dist', 'captchaFonts'),
|
2021-08-21 15:08:28 +00:00
|
|
|
},
|
2022-09-07 00:37:48 +00:00
|
|
|
{
|
|
|
|
from: path.resolve('src', 'data', 'redis', 'lua', 'placePixel.lua'),
|
|
|
|
to: path.resolve('dist', 'workers', 'placePixel.lua'),
|
|
|
|
},
|
2021-03-18 16:15:18 +00:00
|
|
|
],
|
|
|
|
}),
|
2020-12-01 12:11:48 +00:00
|
|
|
],
|
|
|
|
|
2021-02-01 19:16:01 +00:00
|
|
|
stats: {
|
|
|
|
colors: true,
|
|
|
|
reasons: false,
|
|
|
|
hash: false,
|
|
|
|
version: false,
|
|
|
|
chunkModules: false,
|
|
|
|
},
|
2021-01-29 21:46:58 +00:00
|
|
|
|
2021-02-01 19:16:01 +00:00
|
|
|
node: {
|
|
|
|
global: false,
|
|
|
|
__dirname: false,
|
2022-08-16 00:43:48 +00:00
|
|
|
__filename: false,
|
2021-02-01 19:16:01 +00:00
|
|
|
},
|
|
|
|
};
|
2020-12-01 12:11:48 +00:00
|
|
|
};
|