]> Untitled Git - lemmy-ui.git/blob - webpack.config.js
74b181b3005c4e827537efabdffe3c0527127531
[lemmy-ui.git] / webpack.config.js
1 const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2 const nodeExternals = require('webpack-node-externals');
3 const CopyPlugin = require('copy-webpack-plugin');
4 const path = require('path');
5
6 module.exports = function (env, _) {
7   const base = {
8     // mode is set by package.json flags
9     entry: './src/server/index.tsx', // Point to main file
10     output: {
11       path: path.resolve(process.cwd(), 'dist'),
12       filename: 'js/server.js',
13       publicPath: '/',
14     },
15     resolve: {
16       extensions: ['.js', '.jsx', '.ts', '.tsx'],
17     },
18     performance: {
19       hints: false,
20     },
21     module: {
22       rules: [
23         {
24           test: /\.(scss|css)$/i,
25           use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
26         },
27         {
28           test: /\.(js|jsx|tsx|ts)$/, // All ts and tsx files will be process by
29           loaders: 'babel-loader', // first babel-loader, then ts-loader
30           exclude: /node_modules/, // ignore node_modules
31         },
32       ],
33     },
34     devServer: {
35       host: '0.0.0.0',
36       contentBase: 'src/',
37       historyApiFallback: true,
38     },
39     plugins: [
40       new MiniCssExtractPlugin({
41         filename: 'styles/styles.css',
42       }),
43       new CopyPlugin({
44         patterns: [{ from: './src/assets', to: './assets' }],
45       }),
46     ],
47   };
48
49   // server-specific configuration
50   if (env.platform === 'server') {
51     base.target = 'node';
52     base.externals = [nodeExternals(), 'inferno-helmet'];
53   }
54   // client-specific configurations
55   if (env.platform === 'client') {
56     base.entry = './src/client/index.tsx';
57     base.output.filename = 'js/client.js';
58   }
59   return base;
60 };