pixelplanet/webpack.config.web.babel.js

167 lines
3.7 KiB
JavaScript
Raw Normal View History

/*
*/
import path from 'path';
2021-01-29 21:46:58 +00:00
import fs from 'fs';
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';
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();
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: '',
},
};
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
}],
];
export default {
name: 'web',
target: 'node',
2020-12-02 20:20:45 +00:00
context: __dirname,
mode: (isDebug) ? 'development' : 'production',
entry: {
web: [path.resolve(__dirname, 'src', 'web.js')],
2021-02-01 15:52:10 +00:00
backup: [path.resolve(__dirname, 'src', 'backup.js')],
},
output: {
2021-01-29 01:15:33 +00:00
path: path.resolve(__dirname, 'build'),
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'),
],
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,
sourceMap: false,
modules: false,
},
},
],
},
2021-01-29 21:46:58 +00:00
{
test: [/\.po$/],
loader: 'ttag-po-loader',
},
],
},
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'),
],
}),
],
2021-01-29 21:46:58 +00:00
stats: {
colors: true,
reasons: false,
hash: false,
version: false,
timings: true,
chunkModules: false,
},
node: {
global: false,
__filename: false,
__dirname: false,
},
};