| 
									
										
										
										
											2023-01-26 16:28:40 +00:00
										 |  |  | const browserslistToEsbuild = require('browserslist-to-esbuild'); | 
					
						
							| 
									
										
										
										
											2023-06-12 16:22:11 +02:00
										 |  |  | const { ESBuildMinifyPlugin } = require('esbuild-loader'); | 
					
						
							|  |  |  | const webpack = require('webpack'); | 
					
						
							| 
									
										
										
										
											2022-10-27 11:49:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-26 16:28:40 +00:00
										 |  |  | const packageJson = require('./package.json'); | 
					
						
							| 
									
										
										
										
											2021-08-24 10:36:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | const nodeModules = []; | 
					
						
							| 
									
										
										
										
											2023-02-09 16:27:14 +00:00
										 |  |  | [...Object.keys(packageJson.dependencies), ...Object.keys(packageJson.peerDependencies)].forEach( | 
					
						
							|  |  |  |   (module) => { | 
					
						
							|  |  |  |     nodeModules.push(new RegExp(`^${module}(/.+)?$`)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2021-08-24 10:36:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-13 09:31:56 +00:00
										 |  |  | /** @type {Omit<import('webpack').Configuration, 'output'>} */ | 
					
						
							|  |  |  | const baseConfig = { | 
					
						
							| 
									
										
										
										
											2023-04-20 08:37:52 +01:00
										 |  |  |   entry: `${__dirname}/src/index.js`, | 
					
						
							| 
									
										
										
										
											2021-08-24 10:36:38 +02:00
										 |  |  |   externals: nodeModules, | 
					
						
							| 
									
										
										
										
											2021-09-07 14:50:34 +02:00
										 |  |  |   mode: process.env.NODE_ENV, | 
					
						
							| 
									
										
										
										
											2023-01-26 16:28:40 +00:00
										 |  |  |   devtool: process.env.NODE_ENV === 'production' ? false : 'eval-source-map', | 
					
						
							| 
									
										
										
										
											2022-10-27 11:49:35 +02:00
										 |  |  |   optimization: { | 
					
						
							| 
									
										
										
										
											2023-01-26 16:28:40 +00:00
										 |  |  |     minimize: process.env.NODE_ENV === 'production', | 
					
						
							| 
									
										
										
										
											2022-10-27 11:49:35 +02:00
										 |  |  |     minimizer: [ | 
					
						
							|  |  |  |       new ESBuildMinifyPlugin({ | 
					
						
							| 
									
										
										
										
											2023-01-26 16:28:40 +00:00
										 |  |  |         target: browserslistToEsbuild(), | 
					
						
							| 
									
										
										
										
											2022-10-27 11:49:35 +02:00
										 |  |  |       }), | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-08-24 10:36:38 +02:00
										 |  |  |   module: { | 
					
						
							|  |  |  |     rules: [ | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2022-10-27 11:49:35 +02:00
										 |  |  |         test: /\.m?jsx?$/, | 
					
						
							|  |  |  |         use: { | 
					
						
							| 
									
										
										
										
											2023-01-26 16:28:40 +00:00
										 |  |  |           loader: require.resolve('esbuild-loader'), | 
					
						
							| 
									
										
										
										
											2022-10-27 11:49:35 +02:00
										 |  |  |           options: { | 
					
						
							| 
									
										
										
										
											2023-01-26 16:28:40 +00:00
										 |  |  |             loader: 'jsx', | 
					
						
							| 
									
										
										
										
											2023-01-06 11:54:09 +00:00
										 |  |  |             target: browserslistToEsbuild(), | 
					
						
							| 
									
										
										
										
											2022-10-27 11:49:35 +02:00
										 |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-08-24 10:36:38 +02:00
										 |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         test: /\.(png|svg|jpg|gif)$/, | 
					
						
							| 
									
										
										
										
											2023-01-26 16:28:40 +00:00
										 |  |  |         type: 'asset', | 
					
						
							| 
									
										
										
										
											2021-12-14 11:46:47 +01:00
										 |  |  |         parser: { | 
					
						
							|  |  |  |           dataUrlCondition: { | 
					
						
							|  |  |  |             maxSize: 8192, | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2021-08-24 10:36:38 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   plugins: [ | 
					
						
							|  |  |  |     new webpack.EnvironmentPlugin({ | 
					
						
							| 
									
										
										
										
											2023-01-26 16:28:40 +00:00
										 |  |  |       NODE_ENV: 'production', | 
					
						
							| 
									
										
										
										
											2021-08-24 10:36:38 +02:00
										 |  |  |     }), | 
					
						
							|  |  |  |   ], | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2023-01-13 09:31:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @type {import('webpack').Configuration[]} */ | 
					
						
							|  |  |  | const config = [ | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     ...baseConfig, | 
					
						
							|  |  |  |     output: { | 
					
						
							|  |  |  |       path: `${__dirname}/build`, | 
					
						
							|  |  |  |       filename: `helper-plugin.esm.js`, | 
					
						
							|  |  |  |       library: { | 
					
						
							| 
									
										
										
										
											2023-01-26 16:28:40 +00:00
										 |  |  |         type: 'module', | 
					
						
							| 
									
										
										
										
											2023-01-13 09:31:56 +00:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2023-02-09 16:27:14 +00:00
										 |  |  |       environment: { module: true }, | 
					
						
							| 
									
										
										
										
											2023-01-13 09:31:56 +00:00
										 |  |  |     }, | 
					
						
							|  |  |  |     experiments: { | 
					
						
							|  |  |  |       outputModule: true, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     ...baseConfig, | 
					
						
							|  |  |  |     output: { | 
					
						
							|  |  |  |       path: `${__dirname}/build`, | 
					
						
							| 
									
										
										
										
											2023-02-09 16:27:14 +00:00
										 |  |  |       filename: `helper-plugin.js`, | 
					
						
							| 
									
										
										
										
											2023-01-13 09:31:56 +00:00
										 |  |  |       library: { | 
					
						
							| 
									
										
										
										
											2023-01-26 16:28:40 +00:00
										 |  |  |         type: 'commonjs', | 
					
						
							| 
									
										
										
										
											2023-01-13 09:31:56 +00:00
										 |  |  |       }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = config; |