]> Untitled Git - lemmy-ui.git/blob - webpack.config.js
d8f7f15c81c1404a8f4b38115893599001cd8011
[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 { merge } = require('lodash');
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 const base = {
15   output: {
16     filename: 'js/server.js',
17     publicPath: '/',
18   },
19   resolve: {
20     extensions: ['.js', '.jsx', '.ts', '.tsx'],
21   },
22   performance: {
23     hints: false,
24   },
25   module: {
26     rules: [
27       {
28         test: /\.(scss|css)$/i,
29         use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
30       },
31       {
32         test: /\.(js|jsx|tsx|ts)$/, // All ts and tsx files will be process by
33         exclude: /node_modules/, // ignore node_modules
34         loader: 'babel-loader',
35       },
36       // Due to some weird babel issue: https://github.com/webpack/webpack/issues/11467
37       {
38         test: /\.m?js/,
39         resolve: {
40           fullySpecified: false,
41         },
42       },
43     ],
44   },
45   plugins: [
46     new MiniCssExtractPlugin({
47       filename: 'styles/styles.css',
48     }),
49     new CopyPlugin({
50       patterns: [{ from: './src/assets', to: './assets' }],
51     }),
52     new webpack.BannerPlugin({
53       banner,
54     }),
55   ],
56 };
57
58 const createServerConfig = (env, mode) => {
59   const config = merge({}, base, {
60     mode,
61     entry: './src/server/index.tsx',
62     output: {
63       filename: 'js/server.js',
64     },
65     target: 'node',
66     externals: [nodeExternals(), 'inferno-helmet'],
67   });
68
69   if (mode === 'development') {
70     config.cache = {
71       type: 'filesystem',
72       name: 'server',
73     };
74   }
75
76   return config;
77 };
78 const createClientConfig = (env, mode) => {
79   const config = merge({}, base, {
80     mode,
81     entry: './src/client/index.tsx',
82     output: {
83       filename: 'js/client.js',
84     },
85   });
86
87   if (mode === 'development') {
88     config.cache = {
89       type: 'filesystem',
90       name: 'client',
91     };
92   }
93
94   return config;
95 };
96
97 module.exports = (env, properties) => [
98   createServerConfig(env, properties.mode || 'development'),
99   createClientConfig(env, properties.mode || 'development'),
100 ];