]> Untitled Git - lemmy-ui.git/blob - webpack.config.js
Add check for unused languages in update_translations.sh
[lemmy-ui.git] / webpack.config.js
1 const webpack = require('webpack');
2 const MiniCssExtractPlugin = require('mini-css-extract-plugin');
3 const nodeExternals = require('webpack-node-externals');
4 const CopyPlugin = require('copy-webpack-plugin');
5 const RunNodeWebpackPlugin = require('run-node-webpack-plugin');
6 const { merge } = require('lodash');
7
8 const banner = `
9   hash:[contentHash], chunkhash:[chunkhash], name:[name], filebase:[base], query:[query], file:[file]
10   Source code: https://github.com/LemmyNet/lemmy-ui
11   Created by dessalines
12   @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
13   `;
14
15 const base = {
16   output: {
17     filename: 'js/server.js',
18     publicPath: '/',
19   },
20   resolve: {
21     extensions: ['.js', '.jsx', '.ts', '.tsx'],
22   },
23   performance: {
24     hints: false,
25   },
26   module: {
27     rules: [
28       {
29         test: /\.(scss|css)$/i,
30         use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
31       },
32       {
33         test: /\.(js|jsx|tsx|ts)$/, // All ts and tsx files will be process by
34         exclude: /node_modules/, // ignore node_modules
35         loader: 'babel-loader',
36       },
37       // Due to some weird babel issue: https://github.com/webpack/webpack/issues/11467
38       {
39         test: /\.m?js/,
40         resolve: {
41           fullySpecified: false,
42         },
43       },
44     ],
45   },
46   plugins: [
47     new MiniCssExtractPlugin({
48       filename: 'styles/styles.css',
49     }),
50     new CopyPlugin({
51       patterns: [{ from: './src/assets', to: './assets' }],
52     }),
53     new webpack.BannerPlugin({
54       banner,
55     }),
56   ],
57 };
58
59 const createServerConfig = (_env, mode) => {
60   const config = merge({}, base, {
61     mode,
62     entry: './src/server/index.tsx',
63     output: {
64       filename: 'js/server.js',
65     },
66     target: 'node',
67     externals: [nodeExternals(), 'inferno-helmet'],
68   });
69
70   if (mode === 'development') {
71     config.cache = {
72       type: 'filesystem',
73       name: 'server',
74     };
75
76     config.plugins.push(
77       new RunNodeWebpackPlugin({
78         runOnlyInWatchMode: true,
79       })
80     );
81   }
82
83   return config;
84 };
85 const createClientConfig = (_env, mode) => {
86   const config = merge({}, base, {
87     mode,
88     entry: './src/client/index.tsx',
89     output: {
90       filename: 'js/client.js',
91     },
92   });
93
94   if (mode === 'development') {
95     config.cache = {
96       type: 'filesystem',
97       name: 'client',
98     };
99   }
100
101   return config;
102 };
103
104 module.exports = (env, properties) => [
105   createServerConfig(env, properties.mode || 'development'),
106   createClientConfig(env, properties.mode || 'development'),
107 ];