1 import HtmlWebpackPlugin from 'html-webpack-plugin';
2 import webpack from 'webpack';
3 import { WebpackManifestPlugin } from 'webpack-manifest-plugin';
5 import getConfig from '@proton/pack/webpack.config';
6 import { addDevEntry, getIndexChunks } from '@proton/pack/webpack/entries';
9 * There are some specific references to Buffer in the drive application,
10 * e.g. MimeTypes so it has to be polyfilled
12 const result = (env: any): webpack.Configuration => {
13 const config = getConfig(env);
15 config.plugins = config.plugins || [];
17 const htmlPlugin = config.plugins.find((plugin): plugin is HtmlWebpackPlugin => {
18 return plugin instanceof HtmlWebpackPlugin;
21 throw new Error('Missing html plugin');
23 const htmlIndex = config.plugins.indexOf(htmlPlugin);
25 config.plugins.splice(
28 new HtmlWebpackPlugin({
29 filename: 'index.html',
30 template: 'ejs-webpack-loader!src/app.ejs',
31 templateParameters: htmlPlugin.userOptions.templateParameters,
32 scriptLoading: 'defer',
34 chunks: getIndexChunks('index'),
38 config.plugins.splice(
41 new HtmlWebpackPlugin({
42 filename: 'urls.html',
43 template: `ejs-webpack-loader!src/urls.ejs`,
44 templateParameters: htmlPlugin.userOptions.templateParameters,
45 scriptLoading: 'defer',
47 chunks: getIndexChunks('index'),
51 if (env.appMode === 'standalone') {
56 new WebpackManifestPlugin({
57 fileName: 'assets/offline.json',
59 /** exclude sourcemaps and certain assets */
61 file.name.includes('.map') ||
62 file.name.includes('date-fns') ||
63 file.name.includes('locales') ||
64 file.name.includes('downloadSW') ||
65 file.name.includes('.json')
69 if (file.name.includes('.js') || file.name.includes('.css')) {
81 extensions: ['.js', '.tsx', '.ts', '...'], // ... is there to include default extensions for proper building of type script web workers.
83 ...config.resolve?.fallback,
84 buffer: require.resolve('buffer'),
85 path: require.resolve('path-browserify'),
90 new webpack.ProvidePlugin({
91 Buffer: [require.resolve('buffer'), 'Buffer'],
97 export default result;