2020-10-25 19:46:08 +00:00
|
|
|
const webpack = require('webpack');
|
2020-09-07 03:41:46 +00:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const nodeExternals = require('webpack-node-externals');
|
2020-09-10 16:39:01 +00:00
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
2020-10-25 20:14:00 +00:00
|
|
|
const RunNodeWebpackPlugin = require('run-node-webpack-plugin');
|
2020-10-25 19:46:08 +00:00
|
|
|
const { merge } = require('lodash');
|
2020-10-03 16:03:29 +00:00
|
|
|
|
|
|
|
const banner = `
|
2020-10-24 17:12:13 +00:00
|
|
|
hash:[contentHash], chunkhash:[chunkhash], name:[name], filebase:[base], query:[query], file:[file]
|
2020-10-03 16:03:29 +00:00
|
|
|
Source code: https://github.com/LemmyNet/lemmy-ui
|
|
|
|
Created by dessalines
|
|
|
|
@license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
|
|
|
|
`;
|
2020-09-07 03:41:46 +00:00
|
|
|
|
2020-10-25 19:46:08 +00:00
|
|
|
const base = {
|
|
|
|
output: {
|
|
|
|
filename: 'js/server.js',
|
|
|
|
publicPath: '/',
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
|
|
},
|
|
|
|
performance: {
|
|
|
|
hints: false,
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(scss|css)$/i,
|
|
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(js|jsx|tsx|ts)$/, // All ts and tsx files will be process by
|
|
|
|
exclude: /node_modules/, // ignore node_modules
|
|
|
|
loader: 'babel-loader',
|
|
|
|
},
|
|
|
|
// Due to some weird babel issue: https://github.com/webpack/webpack/issues/11467
|
|
|
|
{
|
|
|
|
test: /\.m?js/,
|
|
|
|
resolve: {
|
|
|
|
fullySpecified: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: 'styles/styles.css',
|
|
|
|
}),
|
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [{ from: './src/assets', to: './assets' }],
|
|
|
|
}),
|
|
|
|
new webpack.BannerPlugin({
|
|
|
|
banner,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|
2020-10-25 10:58:47 +00:00
|
|
|
|
2020-10-25 19:46:08 +00:00
|
|
|
const createServerConfig = (env, mode) => {
|
|
|
|
const config = merge({}, base, {
|
|
|
|
mode,
|
|
|
|
entry: './src/server/index.tsx',
|
2020-09-07 03:41:46 +00:00
|
|
|
output: {
|
|
|
|
filename: 'js/server.js',
|
|
|
|
},
|
2020-10-25 19:46:08 +00:00
|
|
|
target: 'node',
|
|
|
|
externals: [nodeExternals(), 'inferno-helmet'],
|
|
|
|
});
|
|
|
|
|
|
|
|
if (mode === 'development') {
|
|
|
|
config.cache = {
|
2020-10-25 10:58:47 +00:00
|
|
|
type: 'filesystem',
|
2020-10-25 19:46:08 +00:00
|
|
|
name: 'server',
|
|
|
|
};
|
2020-10-25 20:14:00 +00:00
|
|
|
|
|
|
|
config.plugins.push(
|
|
|
|
new RunNodeWebpackPlugin({
|
|
|
|
runOnlyInWatchMode: true,
|
|
|
|
})
|
|
|
|
);
|
2020-10-25 19:46:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return config;
|
|
|
|
};
|
|
|
|
const createClientConfig = (env, mode) => {
|
|
|
|
const config = merge({}, base, {
|
|
|
|
mode,
|
|
|
|
entry: './src/client/index.tsx',
|
|
|
|
output: {
|
|
|
|
filename: 'js/client.js',
|
2020-10-25 10:58:47 +00:00
|
|
|
},
|
2020-10-25 19:46:08 +00:00
|
|
|
});
|
2020-09-07 03:41:46 +00:00
|
|
|
|
2020-10-25 19:46:08 +00:00
|
|
|
if (mode === 'development') {
|
|
|
|
config.cache = {
|
|
|
|
type: 'filesystem',
|
|
|
|
name: 'client',
|
|
|
|
};
|
2020-09-07 03:41:46 +00:00
|
|
|
}
|
2020-10-25 19:46:08 +00:00
|
|
|
|
|
|
|
return config;
|
2020-09-07 03:41:46 +00:00
|
|
|
};
|
2020-10-25 19:46:08 +00:00
|
|
|
|
|
|
|
module.exports = (env, properties) => [
|
|
|
|
createServerConfig(env, properties.mode || 'development'),
|
|
|
|
createClientConfig(env, properties.mode || 'development'),
|
|
|
|
];
|