Skip to content

Commit

Permalink
fix: output stats.json from build (#771)
Browse files Browse the repository at this point in the history
closes #770
  • Loading branch information
hugomrdias authored Mar 30, 2021
1 parent ed13f31 commit 3fe7316
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
6 changes: 5 additions & 1 deletion src/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Listr = require('listr')
const esbuild = require('esbuild')
const path = require('path')
const fs = require('fs-extra')
const pascalcase = require('pascalcase')
const bytes = require('bytes')
const { premove: del } = require('premove')
Expand All @@ -28,7 +29,7 @@ const build = async (argv) => {
const globalName = pascalcase(pkg.name)
const umdPre = `(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.${globalName} = factory()}(typeof self !== 'undefined' ? self : this, function () {`
const umdPost = `return ${globalName}}));`
await esbuild.build(merge(
const result = await esbuild.build(merge(
{
entryPoints: [fromRoot('src', argv.tsRepo ? 'index.ts' : 'index.js')],
bundle: true,
Expand All @@ -48,6 +49,9 @@ const build = async (argv) => {
},
argv.fileConfig.build.config
))
if (result.metafile) {
fs.writeJSONSync(path.join(paths.dist, 'stats.json'), result.metafile)
}

return outfile
}
Expand Down
41 changes: 20 additions & 21 deletions src/cmds/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,26 @@ const checkBuiltins = async (argv) => {
}
}

await esbuild.build(
merge(
{
entryPoints: [
fromRoot('src', argv.tsRepo ? 'index.ts' : 'index.js')
],
bundle: true,
mainFields: ['browser', 'module', 'main'],
sourcemap: true,
minify: false,
metafile,
outfile,
plugins: [nodePlugin],
define: {
'process.env.NODE_ENV': '"production"'
}
},
userConfig.build.config
)
)

/** @type {import('esbuild').BuildOptions} */
const esbuildOptions = {
entryPoints: [
fromRoot('src', argv.tsRepo ? 'index.ts' : 'index.js')
],
bundle: true,
mainFields: ['browser', 'module', 'main'],
sourcemap: true,
minify: false,
metafile: true,
outfile,
plugins: [nodePlugin],
define: {
'process.env.NODE_ENV': '"production"'
}
}
const result = await esbuild.build(merge(esbuildOptions, userConfig.build.config))
if (result.metafile) {
fs.writeJSONSync(metafile, result.metafile)
}
const { outputs } = fs.readJSONSync(metafile)

await findBuiltins(nodeBuiltIns)
Expand Down

0 comments on commit 3fe7316

Please sign in to comment.