@bigbinary/neeto-commons-frontend 4.13.76 → 4.13.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configs/esbuild/index.js +2 -1
- package/configs/esbuild/utils.js +49 -2
- package/package.json +2 -1
package/configs/esbuild/index.js
CHANGED
|
@@ -24,6 +24,7 @@ const postCssConfig = require("../../../../../postcss.config.js");
|
|
|
24
24
|
const commonResolve = require("../webpack/resolve.js");
|
|
25
25
|
|
|
26
26
|
const isProduction = process.env.NODE_ENV === "production";
|
|
27
|
+
const enableMetafile = process.argv.includes("--analyze");
|
|
27
28
|
const isWatchMode = process.argv.includes("--watch");
|
|
28
29
|
const assetHost =
|
|
29
30
|
process.env.ASSET_HOST &&
|
|
@@ -39,6 +40,7 @@ const config = {
|
|
|
39
40
|
publicPath: `${assetHost ?? ""}/assets`,
|
|
40
41
|
bundle: true,
|
|
41
42
|
splitting: true,
|
|
43
|
+
metafile: enableMetafile,
|
|
42
44
|
outdir: path.join(process.cwd(), "app/assets/builds"),
|
|
43
45
|
minify: isProduction,
|
|
44
46
|
sourcemap: isWatchMode ? true : "external",
|
|
@@ -68,7 +70,6 @@ const config = {
|
|
|
68
70
|
conditions: ["style"],
|
|
69
71
|
logLevel: isWatchMode ? "info" : "error",
|
|
70
72
|
format: "esm",
|
|
71
|
-
metafile: true,
|
|
72
73
|
platform: "browser",
|
|
73
74
|
mainFields: ["browser", "module", "main"],
|
|
74
75
|
loader: {
|
package/configs/esbuild/utils.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const esbuild = require("esbuild");
|
|
2
2
|
const path = require("path");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const { execSync, spawn } = require("child_process");
|
|
3
5
|
|
|
4
6
|
// colors for console output
|
|
5
7
|
const consoleColors = {
|
|
@@ -19,16 +21,61 @@ const createDefinitions = process => {
|
|
|
19
21
|
|
|
20
22
|
const entryPoint = file => path.join(process.cwd(), file);
|
|
21
23
|
|
|
24
|
+
const writeMetafile = (metafile, outdir) => {
|
|
25
|
+
const metaFilePath = path.join(outdir, "meta.json");
|
|
26
|
+
fs.writeFileSync(metaFilePath, JSON.stringify(metafile, null, 2));
|
|
27
|
+
return metaFilePath;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const generateBundleReport = async (metaFilePath, outdir) => {
|
|
31
|
+
try {
|
|
32
|
+
console.info(
|
|
33
|
+
`${consoleColors.info}[bundle-analyzer]${consoleColors.reset} Generating bundle report...`
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const htmlFilePath = path.join(outdir, "bundle-report.html");
|
|
37
|
+
execSync(
|
|
38
|
+
`npx esbuild-visualizer --metadata ${metaFilePath} --filename ${htmlFilePath}`,
|
|
39
|
+
{ stdio: "inherit" }
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
console.info(
|
|
43
|
+
`${consoleColors.success}[bundle-analyzer]${consoleColors.reset} Bundle report generated at ${htmlFilePath}`
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const command = process.platform === "win32" ? "start" : "open";
|
|
47
|
+
spawn(command, [htmlFilePath], { detached: true, stdio: "ignore" });
|
|
48
|
+
console.info(
|
|
49
|
+
`${consoleColors.success}[bundle-analyzer]${consoleColors.reset} Bundle report opened in browser`
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
return htmlFilePath;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(
|
|
55
|
+
`${consoleColors.error}[bundle-analyzer]${consoleColors.reset} Failed to generate bundle report: ${error.message}`
|
|
56
|
+
);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
22
61
|
const build = async config => {
|
|
23
62
|
try {
|
|
24
63
|
console.info(
|
|
25
64
|
`${consoleColors.info}[esbuild]${consoleColors.reset} Building...`
|
|
26
65
|
);
|
|
27
|
-
|
|
66
|
+
|
|
67
|
+
const result = await esbuild.build(config);
|
|
68
|
+
|
|
69
|
+
if (result.metafile) {
|
|
70
|
+
const metaFilePath = writeMetafile(result.metafile, config.outdir);
|
|
71
|
+
await generateBundleReport(metaFilePath, config.outdir);
|
|
72
|
+
}
|
|
73
|
+
|
|
28
74
|
console.info(
|
|
29
75
|
`${consoleColors.success}[esbuild]${consoleColors.reset} Build successful`
|
|
30
76
|
);
|
|
31
|
-
} catch {
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error(`Build error: ${error.message}`);
|
|
32
79
|
const errorMessage = `${consoleColors.error}[esbuild]${consoleColors.reset} Build failed`;
|
|
33
80
|
throw new Error(errorMessage);
|
|
34
81
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neeto-commons-frontend",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.77",
|
|
4
4
|
"description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
|
|
5
5
|
"repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
|
|
6
6
|
"author": "Amaljith K <amaljith.k@bigbinary.com>",
|
|
@@ -150,6 +150,7 @@
|
|
|
150
150
|
"esbuild-plugins-node-modules-polyfill": "^1.6.8",
|
|
151
151
|
"esbuild-rails": "^1.0.7",
|
|
152
152
|
"esbuild-sass-plugin": "^3.3.1",
|
|
153
|
+
"esbuild-visualizer": "^0.4.0",
|
|
153
154
|
"eslint": "^9.25.1",
|
|
154
155
|
"eslint-config-prettier": "^10.1.2",
|
|
155
156
|
"eslint-plugin-import": "^2.31.0",
|