152 lines
4.1 KiB
JavaScript
152 lines
4.1 KiB
JavaScript
const { merge } = require("webpack-merge");
|
|
const path = require("path");
|
|
const ModuleFederationPlugin = require("webpack").container
|
|
.ModuleFederationPlugin;
|
|
const DefinePlugin = require("webpack").DefinePlugin;
|
|
const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
|
|
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
|
const ExternalTemplateRemotesPlugin = require("external-remotes-plugin");
|
|
const CopyPlugin = require("copy-webpack-plugin");
|
|
const TerserPlugin = require("terser-webpack-plugin");
|
|
const minifyJson = require("@docspace/common/utils/minifyJson");
|
|
const PrebuildWebpackPlugin = require("prebuild-webpack-plugin");
|
|
const beforeBuild = require("@docspace/common/utils/beforeBuild");
|
|
|
|
const sharedDeps = require("@docspace/common/constants/sharedDependencies");
|
|
const baseConfig = require("./webpack.base.js");
|
|
|
|
for (let dep in sharedDeps) {
|
|
sharedDeps[dep].eager = true;
|
|
}
|
|
|
|
const clientConfig = {
|
|
target: "web",
|
|
// mode: "development",
|
|
entry: {
|
|
client: ["./src/client/index.js"],
|
|
},
|
|
devtool: "inline-cheap-module-source-map",
|
|
|
|
output: {
|
|
path: path.resolve(process.cwd(), "dist/client"),
|
|
filename: "static/js/[name].[contenthash].bundle.js",
|
|
publicPath: "/doceditor/",
|
|
chunkFilename: "static/js/[id].[contenthash].js",
|
|
assetModuleFilename: (pathData) => {
|
|
//console.log({ pathData });
|
|
|
|
let result = pathData.filename
|
|
.substr(pathData.filename.indexOf("public/"))
|
|
.split("/")
|
|
.slice(1);
|
|
|
|
result.pop();
|
|
|
|
let folder = result.join("/");
|
|
|
|
folder += result.length === 0 ? "" : "/";
|
|
|
|
return `static/${folder}[name][ext]?hash=[contenthash]`; //`${folder}/[name].[contenthash][ext]`;
|
|
},
|
|
},
|
|
|
|
performance: {
|
|
maxEntrypointSize: 512000,
|
|
maxAssetSize: 512000,
|
|
},
|
|
|
|
module: {
|
|
rules: [
|
|
{
|
|
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",
|
|
],
|
|
},
|
|
],
|
|
},
|
|
|
|
plugins: [
|
|
new CleanWebpackPlugin(),
|
|
new ModuleFederationPlugin({
|
|
name: "editor",
|
|
filename: "remoteEntry.js",
|
|
remotes: {
|
|
client: "client@/remoteEntry.js",
|
|
},
|
|
exposes: {
|
|
"./app": "./src/client/index.js",
|
|
},
|
|
shared: { ...sharedDeps },
|
|
}),
|
|
new ExternalTemplateRemotesPlugin(),
|
|
new CopyPlugin({
|
|
patterns: [
|
|
{
|
|
context: path.resolve(process.cwd(), "public"),
|
|
from: "locales/**/*.json",
|
|
transform: minifyJson,
|
|
},
|
|
],
|
|
}),
|
|
new WebpackManifestPlugin(),
|
|
new PrebuildWebpackPlugin({
|
|
build: async (compiler, compilation, matchedFiles) => {
|
|
await beforeBuild(
|
|
[
|
|
path.join(__dirname, "../public/locales"),
|
|
path.join(__dirname, "../../../public/locales"),
|
|
],
|
|
path.join(__dirname, "../src/autoGeneratedTranslations.js")
|
|
);
|
|
},
|
|
}),
|
|
],
|
|
};
|
|
|
|
module.exports = (env, argv) => {
|
|
if (argv.mode === "production") {
|
|
clientConfig.mode = "production";
|
|
clientConfig.optimization = {
|
|
splitChunks: { chunks: "all" },
|
|
minimize: !env.minimize,
|
|
minimizer: [new TerserPlugin()],
|
|
};
|
|
} else {
|
|
clientConfig.mode = "development";
|
|
clientConfig.devtool = "cheap-module-source-map";
|
|
}
|
|
|
|
clientConfig.plugins = [
|
|
...clientConfig.plugins,
|
|
new DefinePlugin({
|
|
IS_DEVELOPMENT: argv.mode !== "production",
|
|
PORT: process.env.PORT || 5013,
|
|
IS_PERSONAL: env.personal || false,
|
|
}),
|
|
];
|
|
|
|
return merge(baseConfig, clientConfig);
|
|
};
|