2021-03-05 18:15:48 +00:00
|
|
|
const ModuleFederationPlugin = require("webpack").container
|
|
|
|
.ModuleFederationPlugin;
|
2022-01-17 15:36:55 +00:00
|
|
|
const ExternalTemplateRemotesPlugin = require("external-remotes-plugin");
|
2022-02-22 08:43:05 +00:00
|
|
|
const TerserPlugin = require("terser-webpack-plugin");
|
|
|
|
const CopyPlugin = require("copy-webpack-plugin");
|
|
|
|
|
2021-03-26 12:05:41 +00:00
|
|
|
const AppServerConfig = require("@appserver/common/constants/AppServerConfig");
|
2022-02-16 08:21:42 +00:00
|
|
|
const combineUrl = require("@appserver/common/utils/combineUrl");
|
2021-09-10 11:20:19 +00:00
|
|
|
const sharedDeps = require("@appserver/common/constants/sharedDependencies");
|
2022-01-17 15:36:55 +00:00
|
|
|
const path = require("path");
|
|
|
|
const pkg = require("./package.json");
|
2022-02-16 08:21:42 +00:00
|
|
|
const { proxyURL } = AppServerConfig;
|
2021-09-13 09:29:44 +00:00
|
|
|
const deps = pkg.dependencies || {};
|
2021-03-05 18:15:48 +00:00
|
|
|
|
2022-02-24 14:43:46 +00:00
|
|
|
for (dep in sharedDeps) {
|
|
|
|
sharedDeps[dep].eager = true;
|
|
|
|
}
|
|
|
|
|
2022-02-22 08:43:05 +00:00
|
|
|
const config = {
|
|
|
|
target: "web",
|
2021-03-10 15:27:40 +00:00
|
|
|
mode: "development",
|
2022-02-22 08:43:05 +00:00
|
|
|
entry: "./src/client/index.js",
|
|
|
|
|
2022-01-17 15:36:55 +00:00
|
|
|
output: {
|
2022-02-28 15:57:43 +00:00
|
|
|
path: path.resolve(process.cwd(), "clientBuild"),
|
2022-02-22 08:43:05 +00:00
|
|
|
filename: "static/js/[name].[contenthash].bundle.js",
|
|
|
|
publicPath: "/products/files/doceditor/",
|
|
|
|
chunkFilename: "static/js/[id].[contenthash].js",
|
2021-08-11 17:40:31 +00:00
|
|
|
},
|
2021-03-05 18:15:48 +00:00
|
|
|
module: {
|
2022-01-17 15:36:55 +00:00
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|ico)$/i,
|
|
|
|
type: "asset/resource",
|
|
|
|
generator: {
|
|
|
|
filename: "static/images/[hash][ext][query]",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.m?js/,
|
|
|
|
type: "javascript/auto",
|
|
|
|
resolve: {
|
|
|
|
fullySpecified: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.react.svg$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: "@svgr/webpack",
|
|
|
|
options: {
|
|
|
|
svgoConfig: {
|
|
|
|
plugins: [{ removeViewBox: false }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ test: /\.json$/, loader: "json-loader" },
|
|
|
|
{
|
|
|
|
test: /\.css$/i,
|
|
|
|
use: ["style-loader", "css-loader"],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s[ac]ss$/i,
|
|
|
|
use: [
|
|
|
|
// Creates `style` nodes from JS strings
|
|
|
|
"style-loader",
|
|
|
|
// Translates CSS into CommonJS
|
|
|
|
{
|
|
|
|
loader: "css-loader",
|
|
|
|
options: {
|
|
|
|
url: {
|
|
|
|
filter: (url, resourcePath) => {
|
|
|
|
// resourcePath - path to css file
|
|
|
|
|
|
|
|
// Don't handle `/static` urls
|
|
|
|
if (url.startsWith("/static") || url.startsWith("data:")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Compiles Sass to CSS
|
|
|
|
"sass-loader",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
test: /\.(js|jsx)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: "babel-loader",
|
|
|
|
options: {
|
|
|
|
presets: ["@babel/preset-react", "@babel/preset-env"],
|
|
|
|
plugins: [
|
|
|
|
"@babel/plugin-transform-runtime",
|
|
|
|
"@babel/plugin-proposal-class-properties",
|
|
|
|
"@babel/plugin-proposal-export-default-from",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"source-map-loader",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2021-03-05 18:15:48 +00:00
|
|
|
},
|
2022-02-16 08:21:42 +00:00
|
|
|
resolve: {
|
|
|
|
extensions: [".jsx", ".js", ".json"],
|
|
|
|
fallback: {
|
|
|
|
crypto: false,
|
|
|
|
},
|
|
|
|
},
|
2022-02-22 08:43:05 +00:00
|
|
|
performance: {
|
|
|
|
maxEntrypointSize: 512000,
|
|
|
|
maxAssetSize: 512000,
|
|
|
|
},
|
2021-03-05 18:15:48 +00:00
|
|
|
plugins: [
|
2022-02-22 08:43:05 +00:00
|
|
|
//new CleanWebpackPlugin(),
|
2021-03-05 18:15:48 +00:00
|
|
|
new ModuleFederationPlugin({
|
2022-01-17 15:36:55 +00:00
|
|
|
name: "editor",
|
|
|
|
filename: "remoteEntry.js",
|
2021-03-26 12:05:41 +00:00
|
|
|
remotes: {
|
2022-01-17 15:36:55 +00:00
|
|
|
studio: `studio@${combineUrl(proxyURL, "/remoteEntry.js")}`,
|
|
|
|
files: `files@${combineUrl(
|
|
|
|
proxyURL,
|
|
|
|
"/products/files/remoteEntry.js"
|
|
|
|
)}`,
|
2021-03-26 12:05:41 +00:00
|
|
|
},
|
2021-03-05 18:15:48 +00:00
|
|
|
exposes: {
|
2022-02-16 11:16:27 +00:00
|
|
|
"./app": "./src/client/index.js",
|
2021-03-05 18:15:48 +00:00
|
|
|
},
|
|
|
|
shared: {
|
|
|
|
...deps,
|
2021-09-10 11:20:19 +00:00
|
|
|
...sharedDeps,
|
2021-03-05 18:15:48 +00:00
|
|
|
},
|
|
|
|
}),
|
2022-01-17 15:36:55 +00:00
|
|
|
new ExternalTemplateRemotesPlugin(),
|
2022-02-22 08:43:05 +00:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: "public",
|
|
|
|
globOptions: {
|
|
|
|
dot: true,
|
|
|
|
gitignore: true,
|
|
|
|
ignore: ["**/index.html"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
2021-03-05 18:15:48 +00:00
|
|
|
],
|
2022-01-17 15:36:55 +00:00
|
|
|
};
|
2022-02-22 08:43:05 +00:00
|
|
|
|
|
|
|
module.exports = (env, argv) => {
|
|
|
|
if (argv.mode === "production") {
|
|
|
|
config.mode = "production";
|
|
|
|
config.optimization = {
|
|
|
|
splitChunks: { chunks: "all" },
|
|
|
|
minimize: !env.minimize,
|
|
|
|
minimizer: [new TerserPlugin()],
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
config.devtool = "cheap-module-source-map";
|
|
|
|
}
|
|
|
|
|
|
|
|
return config;
|
|
|
|
};
|