1 import HtmlWebpackPlugin from 'html-webpack-plugin';
2 import { produce, setAutoFreeze } from 'immer';
3 import path from 'path';
4 import type { Configuration} from 'webpack';
5 import { ProvidePlugin } from 'webpack';
6 import { InjectManifest } from 'workbox-webpack-plugin';
8 import getConfig from '@proton/pack/webpack.config';
9 import { addDevEntry, getIndexChunks, getSupportedEntry, mergeEntry } from '@proton/pack/webpack/entries';
11 const result = (env: any): Configuration => {
14 return produce(getConfig(env), (config) => {
15 config.plugins = config.plugins || [];
16 config.resolve = config.resolve || {};
17 config.resolve.fallback = config.resolve.fallback || {};
20 config.resolve.fallback.buffer = require.resolve('buffer');
23 // It's required by the lib rfc2047 which is used by mimemessage.js
24 // Without it any mimemessage with an attachment including special char will fail
25 Buffer: [require.resolve('buffer'), 'Buffer'],
29 config.resolve.alias = {
30 'proton-mail': path.resolve(__dirname, 'src/app/'),
31 perf_hooks: path.resolve(__dirname, './perf_hooks_polyfill.ts'),
34 // if (config.mode !== 'development') {
37 swSrc: './src/service-worker.js',
38 swDest: 'service-worker.js',
39 // Any other config if needed.
40 maximumFileSizeToCacheInBytes: 10000000,
45 // The order is important so that the unsupported file is loaded after
46 config.entry = mergeEntry(config.entry, {
47 ['eo-index']: [path.resolve('./src/app/eo.tsx'), getSupportedEntry()],
51 config.devServer.historyApiFallback.rewrites = [{ from: /^\/eo/, to: '/eo.html' }];
53 const htmlPlugin = config.plugins.find((plugin): plugin is HtmlWebpackPlugin => {
54 return plugin instanceof HtmlWebpackPlugin;
57 throw new Error('Missing html plugin');
59 const htmlIndex = config.plugins.indexOf(htmlPlugin);
61 if (env.appMode === 'standalone') {
65 // We keep the order because the other plugins have an impact
66 // Replace the old html webpackplugin with this
67 config.plugins.splice(
70 new HtmlWebpackPlugin({
71 filename: 'index.html',
72 template: path.resolve('./src/app.ejs'),
73 templateParameters: htmlPlugin.userOptions.templateParameters,
74 scriptLoading: 'defer',
75 chunks: getIndexChunks('index'),
79 // Add another webpack plugin on top
80 config.plugins.splice(
83 new HtmlWebpackPlugin({
85 template: path.resolve('./src/eo.ejs'),
86 templateParameters: htmlPlugin.userOptions.templateParameters,
87 scriptLoading: 'defer',
88 chunks: getIndexChunks('eo-index'),
93 config.experiments = { asyncWebAssembly: true };
97 export default result;