Skip to content

Commit

Permalink
Add some comments and log out build stats for each bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
m-allanson committed Jul 1, 2020
1 parent 8a74537 commit 2ad2b5e
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions scripts/bundle-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
/* eslint-disable guard-for-in */
/* eslint-disable node/no-extraneous-require */

const bundleReport = require('@parcel/reporter-cli/lib/bundleReport').default;
const defaultConfigContents = require('@parcel/config-default');
const Parcel = require('@parcel/core').default;
const { createWorkerFarm } = require('@parcel/core');

// TODO: maybe it's worth verifying that all syntaxes are bundled?
// Though this is unlikely to change very often.

const config = {
browser: {
target: { distDir: 'dist' },
Expand All @@ -16,8 +20,8 @@ const config = {
},
'syntax-css-in-js': {
target: { distDir: 'dist' },
entry: 'lib/syntaxes/syntax-less.js',
// dest: 'dist/syntax-less.js',
entry: 'lib/syntaxes/syntax-css-in-js.js',
// dest: 'dist/syntax-css-in-js.js',
},
'syntax-html': {
target: { distDir: 'dist' },
Expand Down Expand Up @@ -51,6 +55,9 @@ const config = {
};

let tasks = [];

// Workers have a startup cost. We can keep the workers around between runs,
// then shut them down when all bundles have been created.
let workerFarm = createWorkerFarm();

for (const module in config) {
Expand All @@ -67,32 +74,35 @@ for (const module in config) {
},
includeNodeModules: true,
isLibrary: false,
logLevel: 'verbose',
logLevel: 'warn',
minify: true,
mode: 'production',
outputFormat: 'esmodule',
patchConsole: false,
workerFarm,
});

return await bundler.run();
const bundleGraph = await bundler.run();
const options = bundler._getResolvedParcelOptions(); // hackety hack. Not a public API

// log stats. This is similar to setting `logLevel: verbose`, but skips the progress spinner
await bundleReport(bundleGraph, options.outputFS, options.projectRoot, options.detailedReport);

return bundleGraph;
};

tasks.push([module, task]);
tasks.push(task);
}

(async () => {
try {
for (const [module, task] of tasks) {
const res = await task();

console.log(res.getBundles()[0].stats);
console.log(`bundled ${module}`, res);
for (const task of tasks) {
await task();
}
} catch (error) {
console.error(error);
} finally {
await workerFarm.end();
await workerFarm.end(); // finished bundling, so we can shut the farm.
}
})();

Expand Down

0 comments on commit 2ad2b5e

Please sign in to comment.