2020-12-01 12:11:48 +00:00
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import path from 'path';
|
2021-01-29 21:46:58 +00:00
|
|
|
import fs from 'fs';
|
2020-12-01 12:11:48 +00:00
|
|
|
import webpack from 'webpack';
|
|
|
|
import nodeExternals from 'webpack-node-externals';
|
|
|
|
import GeneratePackageJsonPlugin from 'generate-package-json-webpack-plugin';
|
|
|
|
|
2021-01-29 21:46:58 +00:00
|
|
|
import patch from './scripts/patch';
|
2020-12-02 20:20:45 +00:00
|
|
|
import pkg from './package.json';
|
2020-12-01 12:11:48 +00:00
|
|
|
|
|
|
|
const isDebug = process.argv.includes('--debug');
|
|
|
|
|
2021-01-29 21:46:58 +00:00
|
|
|
/*
|
|
|
|
* check which ssr translations are available
|
|
|
|
* Maybe we will use thi later to auto-populat src/core/ttag.js
|
|
|
|
*
|
|
|
|
const langDir = path.resolve(__dirname, 'i18n');
|
|
|
|
const langs = fs.readdirSync(langDir)
|
|
|
|
.filter((e) => (e.endsWith('.po') && e.startsWith('ssr')));
|
|
|
|
fs.writeFileSync(path.resolve(langDir, 'ssr-list.json'), JSON.stringify(langs));
|
|
|
|
*/
|
|
|
|
|
|
|
|
patch();
|
|
|
|
|
2020-12-01 12:11:48 +00:00
|
|
|
const basePackageValues = {
|
|
|
|
name: pkg.name,
|
|
|
|
version: pkg.version,
|
|
|
|
private: true,
|
|
|
|
engines: pkg.engines,
|
|
|
|
scripts: {
|
|
|
|
start: 'node --nouse-idle-notification --expose-gc web.js',
|
|
|
|
},
|
|
|
|
dependencies: {
|
2020-12-02 20:20:45 +00:00
|
|
|
mysql2: '',
|
2020-12-01 12:11:48 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const babelPlugins = [
|
|
|
|
'@babel/transform-flow-strip-types',
|
|
|
|
['@babel/plugin-proposal-decorators', { legacy: true }],
|
|
|
|
'@babel/plugin-proposal-function-sent',
|
|
|
|
'@babel/plugin-proposal-export-namespace-from',
|
|
|
|
'@babel/plugin-proposal-numeric-separator',
|
|
|
|
'@babel/plugin-proposal-throw-expressions',
|
|
|
|
['@babel/plugin-proposal-class-properties', { loose: true }],
|
|
|
|
'@babel/proposal-object-rest-spread',
|
|
|
|
// react-optimize
|
|
|
|
'@babel/transform-react-constant-elements',
|
|
|
|
'@babel/transform-react-inline-elements',
|
|
|
|
'transform-react-remove-prop-types',
|
|
|
|
'transform-react-pure-class-to-function',
|
2021-01-29 21:46:58 +00:00
|
|
|
['ttag', {
|
|
|
|
extract: {
|
|
|
|
output: path.resolve(__dirname, 'i18n', 'template-ssr.pot'),
|
|
|
|
},
|
2021-01-30 12:32:46 +00:00
|
|
|
discover: ['t', 'jt'],
|
2021-01-29 21:46:58 +00:00
|
|
|
}],
|
2020-12-01 12:11:48 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'web',
|
|
|
|
target: 'node',
|
|
|
|
|
2020-12-02 20:20:45 +00:00
|
|
|
context: __dirname,
|
2020-12-01 12:11:48 +00:00
|
|
|
mode: (isDebug) ? 'development' : 'production',
|
|
|
|
|
|
|
|
entry: {
|
2021-01-29 01:43:03 +00:00
|
|
|
web: [path.resolve(__dirname, 'src', 'web.js')],
|
2021-02-01 15:52:10 +00:00
|
|
|
backup: [path.resolve(__dirname, 'src', 'backup.js')],
|
2020-12-01 12:11:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
output: {
|
2021-01-29 01:15:33 +00:00
|
|
|
path: path.resolve(__dirname, 'build'),
|
2020-12-01 12:11:48 +00:00
|
|
|
libraryTarget: 'commonjs2',
|
|
|
|
},
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
|
|
|
|
},
|
|
|
|
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(js|jsx|ts|tsx)$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
include: [
|
2021-01-29 01:15:33 +00:00
|
|
|
path.resolve(__dirname, 'src'),
|
2020-12-01 12:11:48 +00:00
|
|
|
],
|
|
|
|
options: {
|
|
|
|
cacheDirectory: isDebug,
|
|
|
|
|
|
|
|
babelrc: false,
|
|
|
|
presets: [
|
|
|
|
['@babel/preset-env', {
|
|
|
|
targets: {
|
|
|
|
node: pkg.engines.node.replace(/^\D+/g, ''),
|
|
|
|
},
|
|
|
|
modules: false,
|
|
|
|
useBuiltIns: false,
|
|
|
|
debug: false,
|
|
|
|
}],
|
|
|
|
'@babel/typescript',
|
|
|
|
'@babel/react',
|
|
|
|
],
|
|
|
|
plugins: babelPlugins,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 1,
|
2020-12-02 22:22:59 +00:00
|
|
|
sourceMap: false,
|
2020-12-01 12:11:48 +00:00
|
|
|
modules: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-01-29 21:46:58 +00:00
|
|
|
{
|
|
|
|
test: [/\.po$/],
|
|
|
|
loader: 'ttag-po-loader',
|
|
|
|
},
|
2020-12-01 12:11:48 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
externals: [
|
|
|
|
/\/proxies\.json$/,
|
|
|
|
/\/canvases\.json$/,
|
|
|
|
/^\.\/styleassets\.json$/,
|
|
|
|
/^\.\/assets\.json$/,
|
|
|
|
nodeExternals(),
|
|
|
|
],
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.NODE_ENV': isDebug ? '"development"' : '"production"',
|
|
|
|
'process.env.BROWSER': false,
|
|
|
|
}),
|
|
|
|
// create package.json for deployment
|
|
|
|
new GeneratePackageJsonPlugin(basePackageValues, {
|
|
|
|
sourcePackageFilenames: [
|
2021-01-29 01:15:33 +00:00
|
|
|
path.resolve(__dirname, 'package.json'),
|
2020-12-01 12:11:48 +00:00
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
|
2021-01-29 21:46:58 +00:00
|
|
|
stats: {
|
|
|
|
colors: true,
|
|
|
|
reasons: false,
|
|
|
|
hash: false,
|
|
|
|
version: false,
|
|
|
|
timings: true,
|
|
|
|
chunkModules: false,
|
|
|
|
},
|
|
|
|
|
2020-12-01 12:11:48 +00:00
|
|
|
node: {
|
|
|
|
global: false,
|
|
|
|
__filename: false,
|
|
|
|
__dirname: false,
|
|
|
|
},
|
|
|
|
};
|