2021-12-21 07:59:11 +00:00
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const ModuleFederationPlugin = require('webpack').container.ModuleFederationPlugin;
|
|
|
|
const DefinePlugin = require('webpack').DefinePlugin;
|
|
|
|
const ExternalTemplateRemotesPlugin = require('external-remotes-plugin');
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
const combineUrl = require('@appserver/common/utils/combineUrl');
|
|
|
|
const AppServerConfig = require('@appserver/common/constants/AppServerConfig');
|
|
|
|
const sharedDeps = require('@appserver/common/constants/sharedDependencies');
|
2021-03-10 15:31:21 +00:00
|
|
|
|
2021-12-21 07:59:11 +00:00
|
|
|
const path = require('path');
|
|
|
|
const pkg = require('./package.json');
|
2021-09-13 09:29:44 +00:00
|
|
|
const deps = pkg.dependencies || {};
|
2021-03-22 14:35:33 +00:00
|
|
|
const homepage = pkg.homepage; //combineUrl(AppServerConfig.proxyURL, pkg.homepage);
|
2021-03-10 15:31:21 +00:00
|
|
|
const title = pkg.title;
|
2021-10-04 14:08:03 +00:00
|
|
|
const version = pkg.version;
|
2021-01-25 21:55:46 +00:00
|
|
|
|
2021-03-01 15:21:40 +00:00
|
|
|
const config = {
|
2021-12-21 07:59:11 +00:00
|
|
|
entry: './src/index',
|
|
|
|
target: 'web',
|
|
|
|
mode: 'development',
|
2021-03-01 15:21:40 +00:00
|
|
|
|
2021-01-25 21:55:46 +00:00
|
|
|
devServer: {
|
2021-09-09 08:28:52 +00:00
|
|
|
devMiddleware: {
|
|
|
|
publicPath: homepage,
|
|
|
|
},
|
|
|
|
static: {
|
2021-12-21 07:59:11 +00:00
|
|
|
directory: path.join(__dirname, 'dist'),
|
2021-09-09 08:28:52 +00:00
|
|
|
publicPath: homepage,
|
|
|
|
},
|
|
|
|
client: {
|
2021-12-21 07:59:11 +00:00
|
|
|
logging: 'info',
|
2021-09-09 08:28:52 +00:00
|
|
|
// Can be used only for `errors`/`warnings`
|
|
|
|
//
|
|
|
|
// overlay: {
|
|
|
|
// errors: true,
|
|
|
|
// warnings: true,
|
|
|
|
// }
|
2021-10-05 11:57:42 +00:00
|
|
|
overlay: {
|
|
|
|
warnings: false,
|
|
|
|
},
|
2021-09-09 08:28:52 +00:00
|
|
|
progress: true,
|
|
|
|
},
|
2021-01-25 21:55:46 +00:00
|
|
|
port: 5001,
|
2021-03-01 19:48:48 +00:00
|
|
|
historyApiFallback: {
|
|
|
|
// Paths with dots should still use the history fallback.
|
|
|
|
// See https://github.com/facebook/create-react-app/issues/387.
|
|
|
|
disableDotRule: true,
|
|
|
|
index: homepage,
|
|
|
|
},
|
2021-01-25 21:55:46 +00:00
|
|
|
hot: false,
|
|
|
|
headers: {
|
2021-12-21 07:59:11 +00:00
|
|
|
'Access-Control-Allow-Origin': '*',
|
|
|
|
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
|
|
|
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
|
2021-01-25 21:55:46 +00:00
|
|
|
},
|
2021-09-09 08:28:52 +00:00
|
|
|
|
|
|
|
open: {
|
|
|
|
target: [`http://localhost:8092`],
|
|
|
|
app: {
|
2021-12-21 07:59:11 +00:00
|
|
|
name: 'google-chrome',
|
|
|
|
arguments: ['--incognito', '--new-window'],
|
2021-09-09 08:28:52 +00:00
|
|
|
},
|
|
|
|
},
|
2020-11-27 17:40:38 +00:00
|
|
|
},
|
|
|
|
resolve: {
|
2021-12-21 07:59:11 +00:00
|
|
|
extensions: ['.jsx', '.js', '.json'],
|
2020-11-27 17:40:38 +00:00
|
|
|
fallback: {
|
|
|
|
crypto: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-01-25 21:55:46 +00:00
|
|
|
output: {
|
2021-12-21 07:59:11 +00:00
|
|
|
publicPath: 'auto',
|
|
|
|
chunkFilename: 'static/js/[id].[contenthash].js',
|
2021-03-16 11:10:20 +00:00
|
|
|
//assetModuleFilename: "static/images/[hash][ext][query]",
|
2021-12-21 07:59:11 +00:00
|
|
|
path: path.resolve(process.cwd(), 'dist'),
|
|
|
|
filename: 'static/js/[name].[contenthash].bundle.js',
|
2020-11-27 17:40:38 +00:00
|
|
|
},
|
|
|
|
|
2021-08-11 17:40:31 +00:00
|
|
|
performance: {
|
|
|
|
maxEntrypointSize: 512000,
|
|
|
|
maxAssetSize: 512000,
|
|
|
|
},
|
|
|
|
|
2020-11-27 17:40:38 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
2021-03-10 16:33:10 +00:00
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|ico)$/i,
|
2021-12-21 07:59:11 +00:00
|
|
|
type: 'asset/resource',
|
2021-03-16 11:10:20 +00:00
|
|
|
generator: {
|
2021-12-21 07:59:11 +00:00
|
|
|
filename: 'static/images/[hash][ext][query]',
|
2021-03-16 11:10:20 +00:00
|
|
|
},
|
2021-03-10 16:33:10 +00:00
|
|
|
},
|
2020-11-27 17:40:38 +00:00
|
|
|
{
|
|
|
|
test: /\.m?js/,
|
2021-12-21 07:59:11 +00:00
|
|
|
type: 'javascript/auto',
|
2020-11-27 17:40:38 +00:00
|
|
|
resolve: {
|
|
|
|
fullySpecified: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.react.svg$/,
|
2021-02-28 18:59:50 +00:00
|
|
|
use: [
|
|
|
|
{
|
2021-12-21 07:59:11 +00:00
|
|
|
loader: '@svgr/webpack',
|
2021-02-28 18:59:50 +00:00
|
|
|
options: {
|
|
|
|
svgoConfig: {
|
|
|
|
plugins: [{ removeViewBox: false }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-11-27 17:40:38 +00:00
|
|
|
},
|
2021-12-21 07:59:11 +00:00
|
|
|
{ test: /\.json$/, loader: 'json-loader' },
|
2020-11-27 17:40:38 +00:00
|
|
|
{
|
|
|
|
test: /\.css$/i,
|
2021-12-21 07:59:11 +00:00
|
|
|
use: ['style-loader', 'css-loader'],
|
2020-11-27 17:40:38 +00:00
|
|
|
},
|
2020-12-01 07:53:38 +00:00
|
|
|
{
|
|
|
|
test: /\.s[ac]ss$/i,
|
|
|
|
use: [
|
|
|
|
// Creates `style` nodes from JS strings
|
2021-12-21 07:59:11 +00:00
|
|
|
'style-loader',
|
2020-12-01 07:53:38 +00:00
|
|
|
// Translates CSS into CommonJS
|
2021-09-10 08:30:27 +00:00
|
|
|
{
|
2021-12-21 07:59:11 +00:00
|
|
|
loader: 'css-loader',
|
2021-09-10 08:30:27 +00:00
|
|
|
options: {
|
|
|
|
url: {
|
|
|
|
filter: (url, resourcePath) => {
|
|
|
|
// resourcePath - path to css file
|
|
|
|
|
|
|
|
// Don't handle `/static` urls
|
2021-12-21 07:59:11 +00:00
|
|
|
if (url.startsWith('/static') || url.startsWith('data:')) {
|
2021-09-10 08:30:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-12-01 07:53:38 +00:00
|
|
|
// Compiles Sass to CSS
|
2021-12-21 07:59:11 +00:00
|
|
|
'sass-loader',
|
2020-12-01 10:02:31 +00:00
|
|
|
],
|
2020-12-01 07:53:38 +00:00
|
|
|
},
|
2020-11-27 17:40:38 +00:00
|
|
|
{
|
|
|
|
test: /\.(js|jsx)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
{
|
2021-12-21 07:59:11 +00:00
|
|
|
loader: 'babel-loader',
|
2020-11-27 17:40:38 +00:00
|
|
|
options: {
|
2021-12-21 07:59:11 +00:00
|
|
|
presets: ['@babel/preset-react', '@babel/preset-env'],
|
2020-11-27 17:40:38 +00:00
|
|
|
plugins: [
|
2021-12-21 07:59:11 +00:00
|
|
|
'@babel/plugin-transform-runtime',
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
'@babel/plugin-proposal-export-default-from',
|
2020-11-27 17:40:38 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2021-12-21 07:59:11 +00:00
|
|
|
'source-map-loader',
|
2020-11-27 17:40:38 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
2021-03-10 15:31:21 +00:00
|
|
|
new CleanWebpackPlugin(),
|
2020-11-27 17:40:38 +00:00
|
|
|
new ModuleFederationPlugin({
|
2021-12-21 07:59:11 +00:00
|
|
|
name: 'studio',
|
|
|
|
filename: 'remoteEntry.js',
|
2020-11-30 08:35:50 +00:00
|
|
|
remotes: {
|
2021-12-21 07:59:11 +00:00
|
|
|
studio: `studio@${combineUrl(AppServerConfig.proxyURL, '/remoteEntry.js')}`,
|
|
|
|
people: `people@${combineUrl(AppServerConfig.proxyURL, '/products/people/remoteEntry.js')}`,
|
2020-11-30 08:35:50 +00:00
|
|
|
},
|
|
|
|
exposes: {
|
2021-12-21 07:59:11 +00:00
|
|
|
'./shell': './src/Shell',
|
|
|
|
'./store': './src/store',
|
|
|
|
'./Error404': './src/components/pages/Errors/404/',
|
|
|
|
'./Error401': './src/components/pages/Errors/401',
|
|
|
|
'./Error403': './src/components/pages/Errors/403',
|
|
|
|
'./Error520': './src/components/pages/Errors/520',
|
|
|
|
'./Layout': './src/components/Layout',
|
|
|
|
'./Layout/context': './src/components/Layout/context.js',
|
|
|
|
'./Main': './src/components/Main',
|
|
|
|
'./toastr': './src/helpers/toastr',
|
2020-11-30 08:35:50 +00:00
|
|
|
},
|
2020-11-27 17:40:38 +00:00
|
|
|
shared: {
|
|
|
|
...deps,
|
2021-09-10 11:20:19 +00:00
|
|
|
...sharedDeps,
|
2020-11-27 17:40:38 +00:00
|
|
|
},
|
|
|
|
}),
|
2021-07-23 14:20:42 +00:00
|
|
|
new ExternalTemplateRemotesPlugin(),
|
2021-01-25 21:55:46 +00:00
|
|
|
new HtmlWebpackPlugin({
|
2021-12-21 07:59:11 +00:00
|
|
|
template: './public/index.html',
|
2021-03-01 15:21:40 +00:00
|
|
|
publicPath: homepage,
|
2021-03-10 15:31:21 +00:00
|
|
|
title: title,
|
2021-03-13 15:31:09 +00:00
|
|
|
base: `${homepage}/`,
|
2021-03-10 15:31:21 +00:00
|
|
|
}),
|
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
2021-12-21 07:59:11 +00:00
|
|
|
from: 'public',
|
2021-03-10 15:31:21 +00:00
|
|
|
globOptions: {
|
|
|
|
dot: true,
|
|
|
|
gitignore: true,
|
2021-12-21 07:59:11 +00:00
|
|
|
ignore: ['**/index.html'],
|
2021-03-10 15:31:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-11-27 17:40:38 +00:00
|
|
|
}),
|
2021-10-04 14:08:03 +00:00
|
|
|
new DefinePlugin({
|
|
|
|
VERSION: JSON.stringify(version),
|
|
|
|
BUILD_AT: DefinePlugin.runtimeValue(function () {
|
|
|
|
const timeElapsed = Date.now();
|
|
|
|
const today = new Date(timeElapsed);
|
2021-12-21 07:59:11 +00:00
|
|
|
return JSON.stringify(today.toISOString().split('.')[0] + 'Z');
|
2021-10-04 14:08:03 +00:00
|
|
|
}, true),
|
|
|
|
}),
|
2020-11-27 17:40:38 +00:00
|
|
|
],
|
|
|
|
};
|
2021-03-01 15:21:40 +00:00
|
|
|
|
|
|
|
module.exports = (env, argv) => {
|
2021-12-21 07:59:11 +00:00
|
|
|
if (argv.mode === 'production') {
|
|
|
|
config.mode = 'production';
|
2021-03-10 15:31:21 +00:00
|
|
|
config.optimization = {
|
2021-12-21 07:59:11 +00:00
|
|
|
splitChunks: { chunks: 'all' },
|
|
|
|
minimize: !env.minimize,
|
2021-11-25 14:39:25 +00:00
|
|
|
minimizer: [new TerserPlugin()],
|
2021-03-10 15:31:21 +00:00
|
|
|
};
|
2021-03-01 15:21:40 +00:00
|
|
|
} else {
|
2021-12-21 07:59:11 +00:00
|
|
|
config.devtool = 'cheap-module-source-map';
|
2021-03-01 15:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return config;
|
|
|
|
};
|