DocSpace-client/web/ASC.Web.Editor/webpack.config.js

88 lines
2.3 KiB
JavaScript
Raw Normal View History

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");
const sharedDeps = require("@appserver/common/constants/sharedDependencies");
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');
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
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: {
devMiddleware: {
publicPath: homepage,
},
static: {
2021-12-21 07:59:11 +00:00
directory: path.join(__dirname, 'dist'),
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
},
},
performance: {
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
2021-03-05 18:15:48 +00:00
module: {
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,
...sharedDeps,
2021-03-05 18:15:48 +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;
};