Skip to content

Commit 3fe7316

Browse files
authored
fix: output stats.json from build (#771)
closes #770
1 parent ed13f31 commit 3fe7316

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

src/build/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const Listr = require('listr')
44
const esbuild = require('esbuild')
55
const path = require('path')
6+
const fs = require('fs-extra')
67
const pascalcase = require('pascalcase')
78
const bytes = require('bytes')
89
const { premove: del } = require('premove')
@@ -28,7 +29,7 @@ const build = async (argv) => {
2829
const globalName = pascalcase(pkg.name)
2930
const umdPre = `(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.${globalName} = factory()}(typeof self !== 'undefined' ? self : this, function () {`
3031
const umdPost = `return ${globalName}}));`
31-
await esbuild.build(merge(
32+
const result = await esbuild.build(merge(
3233
{
3334
entryPoints: [fromRoot('src', argv.tsRepo ? 'index.ts' : 'index.js')],
3435
bundle: true,
@@ -48,6 +49,9 @@ const build = async (argv) => {
4849
},
4950
argv.fileConfig.build.config
5051
))
52+
if (result.metafile) {
53+
fs.writeJSONSync(path.join(paths.dist, 'stats.json'), result.metafile)
54+
}
5155

5256
return outfile
5357
}

src/cmds/check.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,26 @@ const checkBuiltins = async (argv) => {
6969
}
7070
}
7171

72-
await esbuild.build(
73-
merge(
74-
{
75-
entryPoints: [
76-
fromRoot('src', argv.tsRepo ? 'index.ts' : 'index.js')
77-
],
78-
bundle: true,
79-
mainFields: ['browser', 'module', 'main'],
80-
sourcemap: true,
81-
minify: false,
82-
metafile,
83-
outfile,
84-
plugins: [nodePlugin],
85-
define: {
86-
'process.env.NODE_ENV': '"production"'
87-
}
88-
},
89-
userConfig.build.config
90-
)
91-
)
92-
72+
/** @type {import('esbuild').BuildOptions} */
73+
const esbuildOptions = {
74+
entryPoints: [
75+
fromRoot('src', argv.tsRepo ? 'index.ts' : 'index.js')
76+
],
77+
bundle: true,
78+
mainFields: ['browser', 'module', 'main'],
79+
sourcemap: true,
80+
minify: false,
81+
metafile: true,
82+
outfile,
83+
plugins: [nodePlugin],
84+
define: {
85+
'process.env.NODE_ENV': '"production"'
86+
}
87+
}
88+
const result = await esbuild.build(merge(esbuildOptions, userConfig.build.config))
89+
if (result.metafile) {
90+
fs.writeJSONSync(metafile, result.metafile)
91+
}
9392
const { outputs } = fs.readJSONSync(metafile)
9493

9594
await findBuiltins(nodeBuiltIns)

0 commit comments

Comments
 (0)