62 lines
1.7 KiB
JavaScript
62 lines
1.7 KiB
JavaScript
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
|
const nodeExternals = require('webpack-node-externals');
|
|
const StartServerPlugin = require('start-server-webpack-plugin');
|
|
|
|
const config = require('./webpack.common.config');
|
|
const isProduction = !!process.argv.find((arg) => '--production' === arg);
|
|
|
|
if (!isProduction) {
|
|
config.devtool = 'source-map';
|
|
}
|
|
config.entry = {
|
|
server: [
|
|
'source-map-support/register',
|
|
'@babel/polyfill',
|
|
path.join(__dirname, 'register-packets.js'),
|
|
path.join(__dirname, 'register-synchronizeds.js'),
|
|
'@avocado/behavior/item/initialize',
|
|
path.join(__dirname, 'server', 'index.js'),
|
|
],
|
|
};
|
|
if (process.argv.find((arg) => '--hot' === arg)) {
|
|
config.entry.server.unshift('webpack/hot/signal');
|
|
}
|
|
config.externals = [
|
|
nodeExternals({
|
|
whitelist: /(?:@avocado|webpack\/hot\/signal)/,
|
|
}),
|
|
];
|
|
// Babel config file.
|
|
config.module.rules[0].use.options.configFile = path.resolve(
|
|
__dirname, 'babel.server.config.js'
|
|
);
|
|
config.module.rules[1].use.options.paths.push(
|
|
path.resolve(__dirname, 'server'),
|
|
);
|
|
config.module.rules[2].use.options.paths.push(
|
|
path.resolve(__dirname, 'server'),
|
|
);
|
|
config.module.rules[3].use.options.paths.push(
|
|
path.resolve(__dirname, 'server'),
|
|
);
|
|
const nodeArgs = ['--preserve-symlinks'];
|
|
if (process.argv.find((arg) => '--prof' === arg)) {
|
|
nodeArgs.push('--prof');
|
|
}
|
|
if (process.argv.find((arg) => '--autorun' === arg)) {
|
|
config.plugins.push(new StartServerPlugin({
|
|
name: 'server.js',
|
|
nodeArgs: nodeArgs,
|
|
signal: true,
|
|
}));
|
|
}
|
|
config.plugins.push(new webpack.DefinePlugin({
|
|
AVOCADO_CLIENT: false,
|
|
AVOCADO_SERVER: true,
|
|
}));
|
|
config.target = 'node';
|
|
|
|
module.exports = config;
|