DocSpace-buildtools/products/ASC.Files/Client/webpack.config.js

199 lines
5.1 KiB
JavaScript
Raw Normal View History

const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ModuleFederationPlugin = require("webpack").container
.ModuleFederationPlugin;
2021-07-23 14:20:42 +00:00
const ExternalTemplateRemotesPlugin = require("external-remotes-plugin");
2021-03-10 16:07:54 +00:00
const TerserPlugin = require("terser-webpack-plugin");
2021-03-22 14:35:33 +00:00
const combineUrl = require("@appserver/common/utils/combineUrl");
2021-07-23 14:20:42 +00:00
const getUTCString = require("@appserver/common/utils/getUTCString");
2021-03-22 14:35:33 +00:00
const AppServerConfig = require("@appserver/common/constants/AppServerConfig");
2021-03-10 16:07:54 +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-10 16:07:54 +00:00
const title = pkg.title;
var config = {
mode: "development",
entry: "./src/index",
devServer: {
publicPath: homepage,
2021-03-10 16:07:54 +00:00
contentBase: [path.join(__dirname, "dist")],
contentBasePublicPath: homepage,
port: 5008,
historyApiFallback: {
// Paths with dots should still use the history fallback.
// See https://github.com/facebook/create-react-app/issues/387.
disableDotRule: true,
index: homepage,
},
// proxy: [
// {
// context: "/api",
// target: "http://localhost:8092",
// },
// ],
hot: false,
hotOnly: false,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers":
"X-Requested-With, content-type, Authorization",
},
},
output: {
2021-03-10 16:07:54 +00:00
publicPath: "auto",
chunkFilename: "static/js/[id].[contenthash].js",
//assetModuleFilename: "assets/[hash][ext][query]",
path: path.resolve(process.cwd(), "dist"),
filename: "static/js/[name].[contenthash].bundle.js",
},
resolve: {
extensions: [".jsx", ".js", ".json"],
fallback: {
crypto: false,
},
},
module: {
rules: [
2021-03-10 16:07:54 +00:00
{
2021-03-10 16:33:10 +00:00
test: /\.(png|jpe?g|gif|ico)$/i,
2021-03-10 16:07:54 +00:00
type: "asset/resource",
generator: {
filename: "static/images/[hash][ext][query]",
},
2021-03-10 16:07:54 +00:00
},
{
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
"css-loader",
// 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",
],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new ModuleFederationPlugin({
name: "files",
2021-07-23 14:20:42 +00:00
filename: `remoteEntry.js?__hash=${getUTCString()}`,
remotes: {
2021-03-22 14:35:33 +00:00
studio: `studio@${combineUrl(
AppServerConfig.proxyURL,
2021-07-23 14:20:42 +00:00
`/remoteEntry.js?__hash=${getUTCString()}`
2021-03-22 14:35:33 +00:00
)}`,
people: `people@${combineUrl(
AppServerConfig.proxyURL,
2021-07-23 14:20:42 +00:00
`/products/people/remoteEntry.js?__hash=${getUTCString()}`
2021-03-22 14:35:33 +00:00
)}`,
},
exposes: {
"./app": "./src/Files.jsx",
"./SharingDialog": "./src/components/panels/SharingDialog",
},
shared: {
...deps,
react: {
singleton: true,
requiredVersion: deps.react,
},
"react-dom": {
singleton: true,
requiredVersion: deps["react-dom"],
},
},
}),
2021-07-23 14:20:42 +00:00
new ExternalTemplateRemotesPlugin(),
new HtmlWebpackPlugin({
template: "./public/index.html",
publicPath: homepage,
2021-03-10 16:07:54 +00:00
title: title,
base: `${homepage}/`,
}),
new CopyPlugin({
patterns: [
{
from: "public",
globOptions: {
dot: true,
gitignore: true,
ignore: ["**/index.html"],
},
},
],
}),
],
};
module.exports = (env, argv) => {
if (argv.mode === "production") {
config.mode = "production";
2021-03-10 16:07:54 +00:00
config.optimization = {
splitChunks: { chunks: "all" },
minimize: true,
minimizer: [new TerserPlugin()],
};
2021-03-01 15:21:40 +00:00
} else {
2021-03-03 14:58:16 +00:00
config.devtool = "cheap-module-source-map";
}
return config;
};