Web: Doceditor: added simple webpack config
This commit is contained in:
parent
a94022816f
commit
ffc5630958
@ -1,71 +1,25 @@
|
||||
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
||||
const CopyPlugin = require("copy-webpack-plugin");
|
||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||
const ModuleFederationPlugin = require("webpack").container
|
||||
.ModuleFederationPlugin;
|
||||
const ExternalTemplateRemotesPlugin = require("external-remotes-plugin");
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const combineUrl = require("@appserver/common/utils/combineUrl");
|
||||
const AppServerConfig = require("@appserver/common/constants/AppServerConfig");
|
||||
const combineUrl = require("@appserver/common/utils/combineUrl");
|
||||
const sharedDeps = require("@appserver/common/constants/sharedDependencies");
|
||||
|
||||
const { proxyURL } = AppServerConfig;
|
||||
|
||||
const path = require("path");
|
||||
const pkg = require("./package.json");
|
||||
const { proxyURL } = AppServerConfig;
|
||||
const deps = pkg.dependencies || {};
|
||||
const homepage = pkg.homepage; // combineUrl(AppServerConfig.proxyURL, pkg.homepage);
|
||||
const title = pkg.title;
|
||||
|
||||
const config = {
|
||||
entry: "./src/index",
|
||||
target: "web",
|
||||
module.exports = {
|
||||
mode: "development",
|
||||
|
||||
devServer: {
|
||||
devMiddleware: {
|
||||
publicPath: homepage,
|
||||
},
|
||||
static: {
|
||||
directory: path.join(__dirname, "dist"),
|
||||
publicPath: homepage,
|
||||
},
|
||||
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: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
||||
"Access-Control-Allow-Headers":
|
||||
"X-Requested-With, content-type, Authorization",
|
||||
},
|
||||
entry: {
|
||||
client: "./src/client/index.js",
|
||||
},
|
||||
|
||||
resolve: {
|
||||
extensions: [".jsx", ".js", ".json"],
|
||||
fallback: {
|
||||
crypto: false,
|
||||
},
|
||||
},
|
||||
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
//filename: "static/js/[name].js",
|
||||
publicPath: "auto",
|
||||
chunkFilename: "static/js/[id].[contenthash].js",
|
||||
//assetModuleFilename: "static/images/[hash][ext][query]",
|
||||
path: path.resolve(process.cwd(), "dist"),
|
||||
filename: "static/js/[name].[contenthash].bundle.js",
|
||||
filename: "static/scripts/doceditor.[name].js",
|
||||
},
|
||||
|
||||
performance: {
|
||||
maxEntrypointSize: 512000,
|
||||
maxAssetSize: 512000,
|
||||
},
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
@ -148,9 +102,13 @@ const config = {
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
resolve: {
|
||||
extensions: [".jsx", ".js", ".json"],
|
||||
fallback: {
|
||||
crypto: false,
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new CleanWebpackPlugin(),
|
||||
new ModuleFederationPlugin({
|
||||
name: "editor",
|
||||
filename: "remoteEntry.js",
|
||||
@ -162,7 +120,7 @@ const config = {
|
||||
)}`,
|
||||
},
|
||||
exposes: {
|
||||
"./app": "./src/Editor.jsx",
|
||||
"./app": "./src/client.js",
|
||||
},
|
||||
shared: {
|
||||
...deps,
|
||||
@ -170,38 +128,5 @@ const config = {
|
||||
},
|
||||
}),
|
||||
new ExternalTemplateRemotesPlugin(),
|
||||
new HtmlWebpackPlugin({
|
||||
template: "./public/index.html",
|
||||
publicPath: homepage,
|
||||
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";
|
||||
config.optimization = {
|
||||
splitChunks: { chunks: "all" },
|
||||
minimize: !env.minimize,
|
||||
minimizer: [new TerserPlugin()],
|
||||
};
|
||||
} else {
|
||||
config.devtool = "cheap-module-source-map";
|
||||
}
|
||||
|
||||
return config;
|
||||
};
|
3
web/ASC.Web.Editor/webpack.config.js
Normal file
3
web/ASC.Web.Editor/webpack.config.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (env = "production") => {
|
||||
return [require("./webpack.client"), require("./webpack.server")];
|
||||
};
|
96
web/ASC.Web.Editor/webpack.server.js
Normal file
96
web/ASC.Web.Editor/webpack.server.js
Normal file
@ -0,0 +1,96 @@
|
||||
const path = require("path");
|
||||
const nodeExternals = require("webpack-node-externals");
|
||||
|
||||
module.exports = {
|
||||
entry: "./src/index.js",
|
||||
target: "node",
|
||||
externals: [nodeExternals()],
|
||||
mode: "development",
|
||||
output: {
|
||||
path: path.resolve("dist"),
|
||||
filename: "index.js",
|
||||
},
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(png|jpe?g|gif|ico)$/i,
|
||||
type: "asset/resource",
|
||||
generator: {
|
||||
filename: "static/images/[hash][ext][query]",
|
||||
},
|
||||
},
|
||||
{
|
||||
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
|
||||
{
|
||||
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",
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
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",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue
Block a user