DocSpace-client/products/ASC.Mail/Client/webpack.config.js

199 lines
5.0 KiB
JavaScript
Raw Normal View History

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 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-12-21 07:59:11 +00:00
const path = require('path');
const pkg = require('./package.json');
const deps = pkg.dependencies || {};
const homepage = pkg.homepage; // combineUrl(AppServerConfig.proxyURL, pkg.homepage);
const title = pkg.title;
var config = {
2021-12-21 07:59:11 +00:00
mode: 'development',
entry: './src/index',
devServer: {
devMiddleware: {
publicPath: homepage,
},
static: {
2021-12-21 07:59:11 +00:00
directory: path.join(__dirname, 'dist'),
publicPath: homepage,
},
port: 5016,
historyApiFallback: {
// Paths with dots should still use the history fallback.
// See https://github.com/facebook/create-react-app/issues/387.
disableDotRule: true,
index: homepage,
},
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',
},
},
output: {
2021-12-21 07:59:11 +00:00
publicPath: 'auto',
chunkFilename: 'static/js/[id].[contenthash].js',
//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',
},
resolve: {
2021-12-21 07:59:11 +00:00
extensions: ['.jsx', '.js', '.json'],
fallback: {
crypto: false,
},
},
performance: {
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
module: {
rules: [
{
test: /\.(png|jpe?g|gif|ico)$/i,
2021-12-21 07:59:11 +00:00
type: 'asset/resource',
generator: {
2021-12-21 07:59:11 +00:00
filename: 'static/images/[hash][ext][query]',
},
},
{
test: /\.m?js/,
2021-12-21 07:59:11 +00:00
type: 'javascript/auto',
resolve: {
fullySpecified: false,
},
},
{
test: /\.react.svg$/,
use: [
{
2021-12-21 07:59:11 +00:00
loader: '@svgr/webpack',
options: {
svgoConfig: {
plugins: [{ removeViewBox: false }],
},
},
},
],
},
2021-12-21 07:59:11 +00:00
{ test: /\.json$/, loader: 'json-loader' },
{
test: /\.css$/i,
2021-12-21 07:59:11 +00:00
use: ['style-loader', 'css-loader'],
},
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
2021-12-21 07:59:11 +00:00
'style-loader',
// Translates CSS into CommonJS
{
2021-12-21 07:59:11 +00:00
loader: 'css-loader',
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:')) {
return false;
}
return true;
},
},
},
},
// Compiles Sass to CSS
2021-12-21 07:59:11 +00:00
'sass-loader',
],
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
2021-12-21 07:59:11 +00:00
loader: 'babel-loader',
options: {
2021-12-21 07:59:11 +00:00
presets: ['@babel/preset-react', '@babel/preset-env'],
plugins: [
2021-12-21 07:59:11 +00:00
'@babel/plugin-transform-runtime',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-default-from',
],
},
},
2021-12-21 07:59:11 +00:00
'source-map-loader',
],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new ModuleFederationPlugin({
2021-12-21 07:59:11 +00:00
name: 'mail',
filename: 'remoteEntry.js',
remotes: {
2021-12-21 07:59:11 +00:00
studio: `studio@${combineUrl(AppServerConfig.proxyURL, '/remoteEntry.js')}`,
},
exposes: {
2021-12-21 07:59:11 +00:00
'./app': './src/Mail.jsx',
},
shared: {
...deps,
...sharedDeps,
},
}),
2021-07-23 14:20:42 +00:00
new ExternalTemplateRemotesPlugin(),
new HtmlWebpackPlugin({
2021-12-21 07:59:11 +00:00
template: './public/index.html',
publicPath: homepage,
title: title,
base: `${homepage}/`,
}),
new CopyPlugin({
patterns: [
{
2021-12-21 07:59:11 +00:00
from: 'public',
globOptions: {
dot: true,
gitignore: true,
2021-12-21 07:59:11 +00:00
ignore: ['**/index.html'],
},
},
],
}),
],
};
module.exports = (env, argv) => {
2021-12-21 07:59:11 +00:00
if (argv.mode === 'production') {
config.mode = 'production';
config.optimization = {
2021-12-21 07:59:11 +00:00
splitChunks: { chunks: 'all' },
minimize: !env.minimize,
minimizer: [new TerserPlugin()],
};
} else {
2021-12-21 07:59:11 +00:00
config.devtool = 'cheap-module-source-map';
}
return config;
};