Web: Doceditor: modified webpack dev config

This commit is contained in:
Artem Tarasov 2022-07-10 12:53:58 +03:00
parent 2a74e0e8cd
commit a1d599ee43
4 changed files with 4 additions and 200 deletions

View File

@ -2,9 +2,6 @@ const webpack = require("webpack");
const { merge } = require("webpack-merge");
const path = require("path");
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;
@ -15,13 +12,12 @@ const sharedDeps = require("@appserver/common/constants/sharedDependencies");
const ExternalTemplateRemotesPlugin = require("external-remotes-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const pkg = require("../../package.json");
const homepage = pkg.homepage; // combineUrl(proxyURL, pkg.homepage);
const BUILD_DIR = path.resolve(process.cwd(), "dist");
const homepage = pkg.homepage;
for (let dep in sharedDeps) {
sharedDeps[dep].eager = true;
}
//&path=//localhost:5013/__webpack_hmr
const clientConfig = {
target: "web",
mode: "development",
@ -33,9 +29,7 @@ const clientConfig = {
},
devtool: "inline-cheap-module-source-map",
devServer: {
//contentBase: "./dist",
//compress: true,
//historyApiFallback: true,
historyApiFallback: true,
hot: true,
historyApiFallback: {
// Paths with dots should still use the history fallback.
@ -53,15 +47,6 @@ const clientConfig = {
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/",
@ -81,7 +66,6 @@ const clientConfig = {
globOptions: {
dot: true,
gitignore: true,
ignore: ["**/index.html"],
},
},
],
@ -91,7 +75,7 @@ const clientConfig = {
new LoadablePlugin({
outputAsset: false, // to avoid writing loadable-stats in the same output as client
writeToDisk: true,
filename: `${BUILD_DIR}/loadable-stats.json`,
filename: path.resolve(process.cwd(), "dist/client/loadable-stats.json"),
}),
new ModuleFederationPlugin({
name: "editor",

View File

@ -24,9 +24,6 @@ const serverConfig = {
filename: "[name].js",
libraryTarget: "commonjs2",
chunkFilename: "chunks/[name].js",
devtoolModuleFilenameTemplate: (info) =>
path.resolve(info.absoluteResourcePath).replace(/\\/g, "/"),
assetModuleFilename: "assets/[hash][ext][query]",
},
externals: [webpackNodeExternals()],
};

View File

@ -1,132 +0,0 @@
const ModuleFederationPlugin = require("webpack").container
.ModuleFederationPlugin;
const ExternalTemplateRemotesPlugin = require("external-remotes-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const AppServerConfig = require("@appserver/common/constants/AppServerConfig");
const combineUrl = require("@appserver/common/utils/combineUrl");
const sharedDeps = require("@appserver/common/constants/sharedDependencies");
const path = require("path");
const pkg = require("../package.json");
const LoadablePlugin = require("@loadable/webpack-plugin");
const commonConfig = require("./webpack.common");
const { merge } = require("webpack-merge");
const { proxyURL } = AppServerConfig;
const deps = pkg.dependencies || {};
const BUILD_DIR = path.resolve(process.cwd(), "dist");
for (dep in sharedDeps) {
sharedDeps[dep].eager = true;
}
const clientBaseConfig = {
target: "web",
output: {
path: path.resolve(process.cwd(), "dist/client"),
filename: "static/js/[name].[contenthash].bundle.js",
publicPath: "/products/files/doceditor/",
chunkFilename: "static/js/[id].[contenthash].js",
},
module: {
rules: [
{
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
{
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",
],
},
],
},
resolve: {
extensions: [".jsx", ".js", ".json"],
fallback: {
crypto: false,
},
},
performance: {
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
plugins: [
new LoadablePlugin({
outputAsset: false,
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(),
new CopyPlugin({
patterns: [
{
from: "public",
globOptions: {
dot: true,
gitignore: true,
ignore: ["**/index.html"],
},
},
],
}),
],
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: [],
},
};
module.exports = merge(commonConfig, clientBaseConfig);

View File

@ -1,45 +0,0 @@
const scriptExtensions = /\.(tsx|ts|js|jsx|mjs)$/;
const imageExtensions = /\.(bmp|gif|jpg|jpeg|png)$/;
const fontsExtension = /\.(eot|otf|ttf|woff|woff2)$/;
module.exports = {
resolve: {
extensions: [".js", ".jsx", ".json", ".ts", ".tsx"],
fallback: {
crypto: false,
},
},
module: {
rules: [
{
test: scriptExtensions,
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",
],
},
},
],
},
{
test: fontsExtension,
type: "asset",
},
{
test: /\.svg/,
type: "asset/inline",
},
{
test: imageExtensions,
type: "asset/resource",
},
],
},
};