2022-04-22 14:12:46 +00:00
|
|
|
const webpack = require("webpack");
|
|
|
|
const { merge } = require("webpack-merge");
|
|
|
|
const path = require("path");
|
2022-07-01 20:33:35 +00:00
|
|
|
const baseConfig = require("../webpack.base.js");
|
|
|
|
const ROOT_DIR = path.resolve(__dirname, "../../");
|
|
|
|
const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args);
|
|
|
|
//const BUILD_DIR = resolvePath("dist");
|
|
|
|
const LoadablePlugin = require("@loadable/webpack-plugin");
|
|
|
|
const ModuleFederationPlugin = require("webpack").container
|
|
|
|
.ModuleFederationPlugin;
|
|
|
|
const combineUrl = require("@appserver/common/utils/combineUrl");
|
|
|
|
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");
|
2022-04-22 14:12:46 +00:00
|
|
|
const pkg = require("../../package.json");
|
2022-07-01 20:33:35 +00:00
|
|
|
const homepage = pkg.homepage; // combineUrl(proxyURL, pkg.homepage);
|
|
|
|
const BUILD_DIR = path.resolve(process.cwd(), "dist");
|
2022-04-22 14:12:46 +00:00
|
|
|
|
2022-07-01 20:33:35 +00:00
|
|
|
for (let dep in sharedDeps) {
|
|
|
|
sharedDeps[dep].eager = true;
|
|
|
|
}
|
|
|
|
//&path=//localhost:5013/__webpack_hmr
|
2022-04-22 14:12:46 +00:00
|
|
|
const clientConfig = {
|
2022-07-01 20:33:35 +00:00
|
|
|
target: "web",
|
2022-04-22 14:12:46 +00:00
|
|
|
mode: "development",
|
|
|
|
entry: {
|
|
|
|
client: [
|
2022-07-01 20:33:35 +00:00
|
|
|
"webpack-hot-middleware/client?reload=true&noInfo=true&path=//localhost:5013/__webpack_hmr",
|
2022-04-22 14:12:46 +00:00
|
|
|
"./src/client/index.js",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
devtool: "inline-cheap-module-source-map",
|
|
|
|
devServer: {
|
2022-07-01 20:33:35 +00:00
|
|
|
//contentBase: "./dist",
|
|
|
|
//compress: true,
|
|
|
|
//historyApiFallback: true,
|
|
|
|
hot: true,
|
2022-04-22 14:12:46 +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,
|
|
|
|
},
|
2022-07-01 20:33:35 +00:00
|
|
|
static: {
|
|
|
|
directory: path.join(__dirname, "dist"),
|
|
|
|
publicPath: homepage,
|
|
|
|
},
|
|
|
|
devMiddleware: {
|
|
|
|
publicPath: homepage,
|
2022-04-22 14:12:46 +00:00
|
|
|
},
|
2022-07-01 20:33:35 +00:00
|
|
|
port: 5013,
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
// path: resolvePath(BUILD_DIR, "client"),
|
|
|
|
// publicPath: "/client/",
|
|
|
|
// filename: "[name].js",
|
|
|
|
// chunkFilename: "[name].js",
|
|
|
|
// // Point sourcemap entries to original disk location (format as URL on Windows)
|
|
|
|
// devtoolModuleFilenameTemplate: (info) =>
|
|
|
|
// path.resolve(info.absoluteResourcePath).replace(/\\/g, "/"),
|
|
|
|
// assetModuleFilename: "assets/[hash][ext][query]",
|
|
|
|
|
|
|
|
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,
|
2022-04-22 14:12:46 +00:00
|
|
|
},
|
2022-07-01 20:33:35 +00:00
|
|
|
module: {
|
|
|
|
...baseConfig.module,
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: "public",
|
|
|
|
globOptions: {
|
|
|
|
dot: true,
|
|
|
|
gitignore: true,
|
|
|
|
ignore: ["**/index.html"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
|
|
|
//loadable plugin will create all the chunks
|
|
|
|
new LoadablePlugin({
|
|
|
|
outputAsset: false, // to avoid writing loadable-stats in the same output as client
|
|
|
|
writeToDisk: true,
|
|
|
|
filename: `${BUILD_DIR}/loadable-stats.json`,
|
|
|
|
}),
|
|
|
|
new ModuleFederationPlugin({
|
|
|
|
name: "editor",
|
|
|
|
filename: "remoteEntry.js",
|
|
|
|
remotes: {
|
|
|
|
studio: `studio@${combineUrl(proxyURL, "/remoteEntry.js")}`,
|
|
|
|
files: `files@${combineUrl(
|
|
|
|
proxyURL,
|
|
|
|
"/products/files/remoteEntry.js"
|
|
|
|
)}`,
|
|
|
|
},
|
|
|
|
exposes: {
|
|
|
|
"./app": "./src/client/index.js",
|
|
|
|
},
|
|
|
|
shared: { ...sharedDeps },
|
|
|
|
}),
|
|
|
|
new ExternalTemplateRemotesPlugin(),
|
2022-04-22 14:12:46 +00:00
|
|
|
|
2022-07-01 20:33:35 +00:00
|
|
|
// you can add additional plugins here like BundleAnalyzerPlugin, Copy Plugin etc.
|
|
|
|
],
|
|
|
|
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: [],
|
|
|
|
},
|
2022-04-22 14:12:46 +00:00
|
|
|
};
|
|
|
|
|
2022-07-01 20:33:35 +00:00
|
|
|
module.exports = merge(baseConfig, clientConfig);
|