]> Untitled Git - lemmy-ui.git/blob - webpack.config.js
Use urlencode for search queries (fixes #10)
[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:[hash], chunkhash:[chunkhash], name:[name], filebase:[filebase], 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       path: path.resolve(process.cwd(), 'dist'),
20       filename: 'js/server.js',
21       publicPath: '/',
22     },
23     resolve: {
24       extensions: ['.js', '.jsx', '.ts', '.tsx'],
25     },
26     performance: {
27       hints: false,
28     },
29     module: {
30       rules: [
31         {
32           test: /\.(scss|css)$/i,
33           use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
34         },
35         {
36           test: /\.(js|jsx|tsx|ts)$/, // All ts and tsx files will be process by
37           loaders: 'babel-loader', // first babel-loader, then ts-loader
38           exclude: /node_modules/, // ignore node_modules
39         },
40       ],
41     },
42     devServer: {
43       host: '0.0.0.0',
44       contentBase: 'src/',
45       historyApiFallback: true,
46     },
47     plugins: [
48       new MiniCssExtractPlugin({
49         filename: 'styles/styles.css',
50       }),
51       new CopyPlugin({
52         patterns: [{ from: './src/assets', to: './assets' }],
53       }),
54       new webpack.BannerPlugin({
55         banner,
56       }),
57     ],
58   };
59
60   // server-specific configuration
61   if (env.platform === 'server') {
62     base.target = 'node';
63     base.externals = [nodeExternals(), 'inferno-helmet'];
64   }
65   // client-specific configurations
66   if (env.platform === 'client') {
67     base.entry = './src/client/index.tsx';
68     base.output.filename = 'js/client.js';
69   }
70   return base;
71 };