From 4d9422ef0d573c3e8adce05c6fc78fbfbec1c884 Mon Sep 17 00:00:00 2001 From: Artem Tarasov Date: Fri, 15 Jul 2022 18:50:57 +0300 Subject: [PATCH] Web: Doceditor: modified webpack config for client --- .../webpack/prod/webpack.prod.client.js | 17 ----- ...ebpack.dev.client.js => webpack.client.js} | 68 ++++++++++--------- web/ASC.Web.Editor/webpack/webpack.server.js | 19 ++---- 3 files changed, 41 insertions(+), 63 deletions(-) delete mode 100644 web/ASC.Web.Editor/webpack/prod/webpack.prod.client.js rename web/ASC.Web.Editor/webpack/{dev/webpack.dev.client.js => webpack.client.js} (70%) diff --git a/web/ASC.Web.Editor/webpack/prod/webpack.prod.client.js b/web/ASC.Web.Editor/webpack/prod/webpack.prod.client.js deleted file mode 100644 index 668a4dc47c..0000000000 --- a/web/ASC.Web.Editor/webpack/prod/webpack.prod.client.js +++ /dev/null @@ -1,17 +0,0 @@ -const { merge } = require("webpack-merge"); -const TerserPlugin = require("terser-webpack-plugin"); -const baseClientConfig = require("../webpack.base.client"); - -const clientConfig = { - mode: "production", - entry: { client: "./src/client/index.js" }, - devtool: false, - - optimization: { - splitChunks: { chunks: "all" }, - minimize: true, - minimizer: [new TerserPlugin()], - }, -}; - -module.exports = merge(baseClientConfig, clientConfig); diff --git a/web/ASC.Web.Editor/webpack/dev/webpack.dev.client.js b/web/ASC.Web.Editor/webpack/webpack.client.js similarity index 70% rename from web/ASC.Web.Editor/webpack/dev/webpack.dev.client.js rename to web/ASC.Web.Editor/webpack/webpack.client.js index 71afff7f1a..79997a9787 100644 --- a/web/ASC.Web.Editor/webpack/dev/webpack.dev.client.js +++ b/web/ASC.Web.Editor/webpack/webpack.client.js @@ -1,6 +1,5 @@ const { merge } = require("webpack-merge"); const path = require("path"); -const baseConfig = require("../webpack.base.js"); const ModuleFederationPlugin = require("webpack").container .ModuleFederationPlugin; const HotModuleReplacementPlugin = require("webpack") @@ -8,13 +7,15 @@ const HotModuleReplacementPlugin = require("webpack") const DefinePlugin = require("webpack").DefinePlugin; const { WebpackManifestPlugin } = require("webpack-manifest-plugin"); const { CleanWebpackPlugin } = require("clean-webpack-plugin"); +const ExternalTemplateRemotesPlugin = require("external-remotes-plugin"); +const CopyPlugin = require("copy-webpack-plugin"); +const TerserPlugin = require("terser-webpack-plugin"); const combineUrl = require("@appserver/common/utils/combineUrl"); const minifyJson = require("@appserver/common/utils/minifyJson"); const AppServerConfig = require("@appserver/common/constants/AppServerConfig"); const { proxyURL } = AppServerConfig; const sharedDeps = require("@appserver/common/constants/sharedDependencies"); -const ExternalTemplateRemotesPlugin = require("external-remotes-plugin"); -const CopyPlugin = require("copy-webpack-plugin"); +const baseConfig = require("./webpack.base.js"); for (let dep in sharedDeps) { sharedDeps[dep].eager = true; @@ -29,17 +30,17 @@ const clientConfig = { devtool: "inline-cheap-module-source-map", output: { - path: path.resolve(process.cwd(), "dist"), + path: path.resolve(process.cwd(), "dist/client"), filename: "static/js/[name].[contenthash].bundle.js", publicPath: "/products/files/doceditor/", chunkFilename: "static/js/[id].[contenthash].js", }, - resolve: { - ...baseConfig.resolve, - }, - module: { - ...baseConfig.module, + + performance: { + maxEntrypointSize: 512000, + maxAssetSize: 512000, }, + plugins: [ new CleanWebpackPlugin(), new ModuleFederationPlugin({ @@ -72,29 +73,34 @@ const clientConfig = { ], }), new WebpackManifestPlugin(), - new DefinePlugin({ - IS_DEVELOPMENT: process.env.NODE_ENV === "development", - PORT: process.env.PORT, - }), new HotModuleReplacementPlugin(), ], - optimization: { - runtimeChunk: "single", // creates a runtime file to be shared for all generated chunks. - splitChunks: { - chunks: "all", // This indicates which chunks will be selected for optimization. - automaticNameDelimiter: "-", - cacheGroups: { - vendor: { - // to convert long vendor generated large name into vendor.js - test: /[\\/]node_modules[\\/]/, - name: "vendor", - chunks: "all", - }, - }, - }, - minimize: false, - minimizer: [], - }, }; -module.exports = merge(baseConfig, clientConfig); +module.exports = (env, argv) => { + if (argv.mode === "production") { + clientConfig.mode = "production"; + clientConfig.optimization = { + // splitChunks: { chunks: "all" }, + minimize: !env.minimize, + minimizer: [new TerserPlugin()], + }; + clientConfig.plugins = [ + ...clientConfig.plugins, + new DefinePlugin({ + IS_DEVELOPMENT: false, + }), + ]; + } else { + clientConfig.devtool = "cheap-module-source-map"; + clientConfig.plugins = [ + ...clientConfig.plugins, + new DefinePlugin({ + IS_DEVELOPMENT: true, + PORT: process.env.PORT || 5013, + }), + ]; + } + + return merge(baseConfig, clientConfig); +}; diff --git a/web/ASC.Web.Editor/webpack/webpack.server.js b/web/ASC.Web.Editor/webpack/webpack.server.js index a10dbf2b63..f1936b7351 100644 --- a/web/ASC.Web.Editor/webpack/webpack.server.js +++ b/web/ASC.Web.Editor/webpack/webpack.server.js @@ -12,14 +12,9 @@ const serverConfig = { entry: { server: "./src/server/index.js", }, - resolve: { - ...baseConfig.resolve, - }, - module: { - ...baseConfig.module, - }, + output: { - path: path.resolve(process.cwd(), "dist/server"), + path: path.resolve(process.cwd(), "dist/"), filename: "[name].js", libraryTarget: "commonjs2", chunkFilename: "chunks/[name].js", @@ -29,19 +24,13 @@ const serverConfig = { module.exports = (env, argv) => { if (argv.mode === "production") { - baseConfig.mode = "production"; - baseConfig.optimization = { - splitChunks: { chunks: "all" }, - minimize: !env.minimize, - minimizer: [new TerserPlugin()], - }; - baseConfig.plugins = [ + serverConfig.plugins = [ new DefinePlugin({ IS_DEVELOPMENT: false, }), ]; } else { - baseConfig.plugins = [ + serverConfig.plugins = [ new DefinePlugin({ IS_DEVELOPMENT: true, }),