| 
									
										
										
										
											2020-10-27 11:27:17 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  | /* eslint-disable import/no-extraneous-dependencies */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 17:13:14 +02:00
										 |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  | const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); | 
					
						
							| 
									
										
										
										
											2021-05-03 16:33:46 +02:00
										 |  |  | const { DuplicateReporterPlugin } = require('duplicate-dependencies-webpack-plugin'); | 
					
						
							| 
									
										
										
										
											2022-03-18 16:13:47 +01:00
										 |  |  | const getPluginsPath = require('./utils/get-plugins-path'); | 
					
						
							| 
									
										
										
										
											2021-06-23 20:18:13 +02:00
										 |  |  | const webpackConfig = require('./webpack.config'); | 
					
						
							| 
									
										
										
										
											2019-05-20 17:13:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | module.exports = () => { | 
					
						
							| 
									
										
										
										
											2021-01-25 14:37:57 +01:00
										 |  |  |   const analyzeBundle = process.env.ANALYZE_BUNDLE; | 
					
						
							| 
									
										
										
										
											2021-05-03 16:33:46 +02:00
										 |  |  |   const analyzeDuplicateDependencies = process.env.ANALYZE_DEPS; | 
					
						
							| 
									
										
										
										
											2022-03-18 16:13:47 +01:00
										 |  |  |   const entry = path.join(__dirname, 'admin', 'src'); | 
					
						
							| 
									
										
										
										
											2019-05-20 17:13:14 +02:00
										 |  |  |   const dest = path.join(__dirname, 'build'); | 
					
						
							| 
									
										
										
										
											2021-01-25 14:37:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // When running the analyze:bundle command, it needs a production build
 | 
					
						
							|  |  |  |   // to display the tree map of modules
 | 
					
						
							|  |  |  |   const env = analyzeBundle ? 'production' : 'development'; | 
					
						
							| 
									
										
										
										
											2019-05-20 17:13:14 +02:00
										 |  |  |   const options = { | 
					
						
							|  |  |  |     backend: 'http://localhost:1337', | 
					
						
							| 
									
										
										
										
											2021-05-05 10:48:27 +02:00
										 |  |  |     adminPath: '/admin/', | 
					
						
							| 
									
										
										
										
											2022-07-27 23:32:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Ideally this would take more scenarios into account, such | 
					
						
							|  |  |  |      * as the `telemetryDisabled` property in the package.json | 
					
						
							|  |  |  |      * of the users project. For builds based on an app we are | 
					
						
							|  |  |  |      * passing this information throgh, but here we do not have access | 
					
						
							|  |  |  |      * to the app's package.json. By using at least an environment variable | 
					
						
							|  |  |  |      * we can make sure developers can actually test this functionality in | 
					
						
							|  |  |  |      * dev-mode. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     telemetryDisabled: process.env.STRAPI_TELEMETRY_DISABLED === 'true', | 
					
						
							| 
									
										
										
										
											2019-05-20 17:13:14 +02:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2022-03-18 16:13:47 +01:00
										 |  |  |   const pluginsPath = getPluginsPath(); | 
					
						
							| 
									
										
										
										
											2019-05-20 17:13:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const args = { | 
					
						
							|  |  |  |     entry, | 
					
						
							| 
									
										
										
										
											2021-09-09 11:23:29 +02:00
										 |  |  |     cacheDir: __dirname, | 
					
						
							| 
									
										
										
										
											2022-03-18 16:13:47 +01:00
										 |  |  |     pluginsPath, | 
					
						
							| 
									
										
										
										
											2019-05-20 17:13:14 +02:00
										 |  |  |     dest, | 
					
						
							|  |  |  |     env, | 
					
						
							|  |  |  |     options, | 
					
						
							| 
									
										
										
										
											2022-04-14 10:59:42 +02:00
										 |  |  |     tsConfigFilePath: path.resolve(__dirname, 'admin', 'src', 'tsconfig.json'), | 
					
						
							| 
									
										
										
										
											2019-05-20 17:13:14 +02:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-25 14:37:57 +01:00
										 |  |  |   const config = webpackConfig(args); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (analyzeBundle) { | 
					
						
							|  |  |  |     config.plugins.push(new BundleAnalyzerPlugin()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-03 16:33:46 +02:00
										 |  |  |   if (analyzeDuplicateDependencies === 'true') { | 
					
						
							|  |  |  |     config.plugins.push(new DuplicateReporterPlugin()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 17:13:14 +02:00
										 |  |  |   return { | 
					
						
							| 
									
										
										
										
											2021-01-25 14:37:57 +01:00
										 |  |  |     ...config, | 
					
						
							| 
									
										
										
										
											2021-11-09 15:55:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 17:13:14 +02:00
										 |  |  |     devServer: { | 
					
						
							|  |  |  |       port: 4000, | 
					
						
							| 
									
										
										
										
											2021-11-09 15:55:30 +01:00
										 |  |  |       client: { | 
					
						
							|  |  |  |         logging: 'none', | 
					
						
							|  |  |  |         overlay: { | 
					
						
							|  |  |  |           errors: true, | 
					
						
							|  |  |  |           warnings: false, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2019-05-20 17:13:14 +02:00
										 |  |  |       historyApiFallback: { | 
					
						
							|  |  |  |         index: '/admin/', | 
					
						
							| 
									
										
										
										
											2019-11-05 09:07:03 +01:00
										 |  |  |         disableDotRule: true, | 
					
						
							| 
									
										
										
										
											2019-05-20 17:13:14 +02:00
										 |  |  |       }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }; |