2021-03-05 18:15:48 +00:00
|
|
|
const ModuleFederationPlugin = require("webpack").container
|
|
|
|
.ModuleFederationPlugin;
|
2021-03-10 15:27:40 +00:00
|
|
|
const TerserPlugin = require("terser-webpack-plugin");
|
2021-03-26 12:05:41 +00:00
|
|
|
const combineUrl = require("@appserver/common/utils/combineUrl");
|
|
|
|
const AppServerConfig = require("@appserver/common/constants/AppServerConfig");
|
2021-09-10 11:20:19 +00:00
|
|
|
const sharedDeps = require("@appserver/common/constants/sharedDependencies");
|
|
|
|
|
2021-04-30 15:01:16 +00:00
|
|
|
const { proxyURL } = AppServerConfig;
|
2021-03-10 15:27:40 +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-05 18:15:48 +00:00
|
|
|
|
2022-01-11 09:57:07 +00:00
|
|
|
const { merge } = require("webpack-merge");
|
|
|
|
const common = require("./webpack/common");
|
|
|
|
const { client: clientLoaders } = require("./webpack/loaders");
|
|
|
|
|
|
|
|
const config = merge(common, {
|
2021-03-05 18:15:48 +00:00
|
|
|
entry: "./src/index",
|
2021-03-10 15:27:40 +00:00
|
|
|
mode: "development",
|
2021-03-05 18:15:48 +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,
|
|
|
|
},
|
2021-03-05 18:15:48 +00:00
|
|
|
port: 5013,
|
|
|
|
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',
|
2021-03-05 18:15:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-08-11 17:40:31 +00:00
|
|
|
performance: {
|
|
|
|
maxEntrypointSize: 512000,
|
|
|
|
maxAssetSize: 512000,
|
|
|
|
},
|
|
|
|
|
2021-03-05 18:15:48 +00:00
|
|
|
module: {
|
2022-01-11 09:57:07 +00:00
|
|
|
rules: clientLoaders,
|
2021-03-05 18:15:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new ModuleFederationPlugin({
|
2021-12-21 07:59:11 +00:00
|
|
|
name: 'editor',
|
|
|
|
filename: 'remoteEntry.js',
|
2021-03-26 12:05:41 +00:00
|
|
|
remotes: {
|
2021-12-21 07:59:11 +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: {
|
2021-12-21 07:59:11 +00:00
|
|
|
'./app': './src/Editor.jsx',
|
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-11 09:57:07 +00:00
|
|
|
});
|
2021-03-05 18:15:48 +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:27:40 +00:00
|
|
|
config.optimization = {
|
2021-12-21 07:59:11 +00:00
|
|
|
splitChunks: { chunks: 'all' },
|
|
|
|
minimize: !env.minimize,
|
2021-03-10 15:27:40 +00:00
|
|
|
minimizer: [new TerserPlugin()],
|
|
|
|
};
|
2021-03-05 18:15:48 +00:00
|
|
|
} else {
|
2021-12-21 07:59:11 +00:00
|
|
|
config.devtool = 'cheap-module-source-map';
|
2021-03-05 18:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return config;
|
|
|
|
};
|