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