From 0ca6fd248ad1379d6f723e3b3524e4699af186bb Mon Sep 17 00:00:00 2001 From: smitJiwani Date: Wed, 27 Dec 2023 19:42:45 +0530 Subject: [PATCH 01/13] feat: added png, jpg and other media files. Added parser for asset/resourse or asset/inline. Added MiniCssExtractPlugin. --- client/package.json | 1 + .../packages/excalidraw/webpack.dev.config.js | 4 +++ .../excalidraw/webpack.prod.config.js | 28 +++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/client/package.json b/client/package.json index 727a088736..5f1b13564e 100644 --- a/client/package.json +++ b/client/package.json @@ -89,6 +89,7 @@ "jest-canvas-mock": "^2.4.0", "lint-staged": "^12.3.7", "lodash": "^4.17.21", + "mini-css-extract-plugin": "^2.7.6", "node-sass": "^7.0.3", "pepjs": "^0.5.3", "prettier": "^2.6.2", diff --git a/client/src/packages/excalidraw/webpack.dev.config.js b/client/src/packages/excalidraw/webpack.dev.config.js index 9e8180f5f3..4a45b3a663 100644 --- a/client/src/packages/excalidraw/webpack.dev.config.js +++ b/client/src/packages/excalidraw/webpack.dev.config.js @@ -59,6 +59,10 @@ module.exports = { test: /\.(woff|woff2|eot|ttf|otf)$/, type: "asset/resource", }, + { + test: /\.(png|svg|jpg|jpeg|gif)$/i, + type: "asset/resource", + }, ], }, optimization: { diff --git a/client/src/packages/excalidraw/webpack.prod.config.js b/client/src/packages/excalidraw/webpack.prod.config.js index 0450d36fab..119a06cfca 100644 --- a/client/src/packages/excalidraw/webpack.prod.config.js +++ b/client/src/packages/excalidraw/webpack.prod.config.js @@ -5,6 +5,7 @@ const BundleAnalyzerPlugin = const autoprefixer = require("autoprefixer"); const webpack = require("webpack"); const { parseEnvVariables } = require("./env"); +const MiniCssExtractPlugin = require("mini-css-extract-plugin"); module.exports = { mode: "production", @@ -29,7 +30,9 @@ module.exports = { test: /\.(sa|sc|c)ss$/, exclude: /node_modules/, use: [ - "style-loader", + MiniCssExtractPlugin.loader, + //mini-css-extract-plugin extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. + //smaller bundle size { loader: "css-loader", }, @@ -71,9 +74,26 @@ module.exports = { }, ], }, + // Rule for PNG, JPEG, and other media files + { + test: /\.(png|jpe?g|gif|svg|ico|webp)$/i, + type: "asset", + // the parser object allows you to specify 8kb as the maximum size + // if the file is greater than 8kb, it will emit a separate file(asset/resourse) else it will be inlined(asset/inline) + parser: { + dataUrlCondition: { + maxSize: 8 * 1024, // 8kb + }, + }, + }, { test: /\.(woff|woff2|eot|ttf|otf)$/, - type: "asset/resource", + type: "asset", + parser: { + dataUrlCondition: { + maxSize: 8 * 1024, // 8kb + }, + }, }, ], }, @@ -101,6 +121,10 @@ module.exports = { path.resolve(__dirname, "../../../.env.production"), ), }), + new MiniCssExtractPlugin({ + filename: "[name].css", + chunkFilename: "excalidraw-assets/[name]-[contenthash].css", + }), ], externals: { react: { From 0cd652949e52466bd4b7dca08765a8fd2d3999e1 Mon Sep 17 00:00:00 2001 From: smitJiwani Date: Thu, 28 Dec 2023 15:36:58 +0530 Subject: [PATCH 02/13] feat: added png, jpg and other media files. Added parser for asset/resourse or asset/inline. Added MiniCssExtractPlugin. v2 --- client/webpack.config.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/client/webpack.config.js b/client/webpack.config.js index ffc5e5d64c..647c4e5def 100644 --- a/client/webpack.config.js +++ b/client/webpack.config.js @@ -1,6 +1,7 @@ import path from "path"; import webpack from "webpack"; import CopyPlugin from "copy-webpack-plugin"; +import miniCssExtractPlugin from "mini-css-extract-plugin"; const isEnvDevelopment = process.env.NODE_ENV !== "production"; const isEnvProduction = process.env.NODE_ENV === "production"; @@ -31,7 +32,7 @@ export default { test: /\.scss$/, use: [ // Adds the styles to the DOM by injecting a