2020-10-27 11:27:17 +01:00
|
|
|
'use strict';
|
|
|
|
|
2019-05-20 17:13:14 +02:00
|
|
|
const path = require('path');
|
2022-03-18 15:21:20 +01:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
|
|
|
// eslint-disable-next-line node/no-extraneous-require
|
|
|
|
const glob = require('glob');
|
2021-01-25 14:37:57 +01:00
|
|
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
2021-05-03 16:33:46 +02:00
|
|
|
const { DuplicateReporterPlugin } = require('duplicate-dependencies-webpack-plugin');
|
|
|
|
|
2021-06-23 20:18:13 +02:00
|
|
|
const webpackConfig = require('./webpack.config');
|
2019-05-20 17:13:14 +02:00
|
|
|
|
2022-03-18 15:21:20 +01:00
|
|
|
const getPluginsPath = () => {
|
|
|
|
const rootPath = path.join('..', '..', '..', 'packages');
|
|
|
|
const corePath = path.join(rootPath, 'core', '*');
|
|
|
|
const pluginsPath = path.join(rootPath, 'plugins', '*');
|
|
|
|
const corePackageDirs = glob.sync(corePath);
|
|
|
|
const pluginsPackageDirs = glob.sync(pluginsPath);
|
|
|
|
const packageDirs = [...corePackageDirs, ...pluginsPackageDirs].filter(dir => {
|
|
|
|
const isCoreAdmin = dir.includes('packages/core/admin/');
|
|
|
|
const pathToEntryPoint = path.join(dir, 'admin', 'src', 'index.js');
|
|
|
|
const doesAdminFolderExist = fs.pathExistsSync(pathToEntryPoint);
|
|
|
|
|
|
|
|
return !isCoreAdmin && doesAdminFolderExist;
|
|
|
|
});
|
|
|
|
|
|
|
|
return packageDirs.map(dir => path.resolve(__dirname, path.join(dir, 'admin', 'src')));
|
|
|
|
};
|
|
|
|
|
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 15:21:20 +01:00
|
|
|
// Directly inject a polyfill in the webpack entry point before the entry point
|
|
|
|
// FIXME: I have noticed a bug regarding the helper-plugin and esbuild-loader
|
|
|
|
// The only I could fix it was to inject the babel polyfill
|
|
|
|
const babelPolyfill = '@babel/polyfill/dist/polyfill.min.js';
|
|
|
|
const entry = [babelPolyfill, 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/',
|
2019-05-20 17:13:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const args = {
|
|
|
|
entry,
|
2021-09-09 11:23:29 +02:00
|
|
|
cacheDir: __dirname,
|
2022-03-18 15:21:20 +01:00
|
|
|
pluginsPath: getPluginsPath(),
|
2019-05-20 17:13:14 +02:00
|
|
|
dest,
|
|
|
|
env,
|
|
|
|
options,
|
|
|
|
};
|
|
|
|
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|