]> Untitled Git - lemmy-ui.git/blob - webpack.config.js
1b3470507a3bc061e13b7b9695e53223d76209c1
[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 const webpack = require('webpack');
6
7 const banner = `
8   hash:[contentHash], chunkhash:[chunkhash], name:[name], filebase:[base], query:[query], file:[file]
9   Source code: https://github.com/LemmyNet/lemmy-ui
10   Created by dessalines
11   @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
12   `;
13
14 module.exports = function (env, _) {
15   const base = {
16     // mode is set by package.json flags
17     entry: './src/server/index.tsx', // Point to main file
18     output: {
19       filename: 'js/server.js',
20       publicPath: '/',
21     },
22     resolve: {
23       extensions: ['.js', '.jsx', '.ts', '.tsx'],
24     },
25     performance: {
26       hints: false,
27     },
28     module: {
29       rules: [
30         {
31           test: /\.(scss|css)$/i,
32           use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
33         },
34         {
35           test: /\.(js|jsx|tsx|ts)$/, // All ts and tsx files will be process by
36           exclude: /node_modules/, // ignore node_modules
37           loader: 'babel-loader',
38         },
39         // Due to some weird babel issue: https://github.com/webpack/webpack/issues/11467
40         {
41           test: /\.m?js/,
42           resolve: {
43             fullySpecified: false,
44           },
45         },
46       ],
47     },
48     devServer: {
49       host: '0.0.0.0',
50       contentBase: 'src/',
51       historyApiFallback: true,
52     },
53     plugins: [
54       new MiniCssExtractPlugin({
55         filename: 'styles/styles.css',
56       }),
57       new CopyPlugin({
58         patterns: [{ from: './src/assets', to: './assets' }],
59       }),
60       new webpack.BannerPlugin({
61         banner,
62       }),
63     ],
64   };
65
66   // server-specific configuration
67   if (env.platform === 'server') {
68     base.target = 'node';
69     base.externals = [nodeExternals(), 'inferno-helmet'];
70   }
71   // client-specific configurations
72   if (env.platform === 'client') {
73     base.entry = './src/client/index.tsx';
74     base.output.filename = 'js/client.js';
75   }
76   return base;
77 };