Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / wallet / webpack.config.ts
blobf9430fff5a3fc4ad992fbf94fe20de9fe4ab7afe
1 import HtmlWebpackPlugin from 'html-webpack-plugin';
2 import webpack from 'webpack';
4 import getConfig from '@proton/pack/webpack.config';
5 import { addDevEntry, getIndexChunks } from '@proton/pack/webpack/entries';
7 const result = (env: any): webpack.Configuration => {
8     const config = getConfig(env);
10     config.plugins = config.plugins || [];
12     const htmlPlugin = config.plugins.find((plugin): plugin is HtmlWebpackPlugin => {
13         return plugin instanceof HtmlWebpackPlugin;
14     });
15     if (!htmlPlugin) {
16         throw new Error('Missing html plugin');
17     }
18     const htmlIndex = config.plugins.indexOf(htmlPlugin);
20     config.plugins.splice(
21         htmlIndex,
22         1,
23         new HtmlWebpackPlugin({
24             filename: 'index.html',
25             template: 'ejs-webpack-loader!src/app.ejs',
26             templateParameters: htmlPlugin.userOptions.templateParameters,
27             scriptLoading: 'defer',
28             inject: 'body',
29             chunks: getIndexChunks('index'),
30         })
31     );
33     if (env.appMode === 'standalone') {
34         addDevEntry(config);
35     }
37     return {
38         ...config,
39         resolve: {
40             ...config.resolve,
41             extensions: ['.js', '.tsx', '.ts', '.wasm'], // ... is there to include default extensions for proper building of type script web workers.
42             fallback: {
43                 ...config.resolve?.fallback,
44                 buffer: require.resolve('buffer'),
45                 path: require.resolve('path-browserify'),
46             },
47         },
48         experiments: { asyncWebAssembly: true },
49         plugins: [
50             ...config.plugins,
51             new webpack.ProvidePlugin({
52                 Buffer: [require.resolve('buffer'), 'Buffer'],
53             }),
54         ],
55     };
58 export default result;