-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: esm version
dist/mqtt.esm.js
and replace browserify
with `e…
…sbuild` (#1731)
- Loading branch information
1 parent
69c51c6
commit 3d6c3be
Showing
8 changed files
with
1,199 additions
and
4,545 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
/dist/ | ||
/build/ | ||
|
||
*.js | ||
*.js | ||
*.mjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const { build } = require('esbuild') | ||
const { polyfillNode } = require('esbuild-plugin-polyfill-node'); | ||
const { rimraf } = require('rimraf') | ||
const fs = require('fs') | ||
|
||
const outdir = 'dist' | ||
|
||
/** | ||
* @type {import('esbuild').BuildOptions} | ||
*/ | ||
const options = { | ||
entryPoints: ['build/mqtt.js'], | ||
bundle: true, | ||
outfile: `${outdir}/mqtt.js`, | ||
format: 'iife', | ||
platform: 'browser', | ||
globalName: 'mqtt', | ||
define: { | ||
'global': 'window' | ||
}, | ||
plugins: [ | ||
polyfillNode({ | ||
polyfills: [ | ||
'readable-stream' | ||
] | ||
}), | ||
], | ||
} | ||
|
||
async function run() { | ||
const start = Date.now() | ||
await rimraf(outdir) | ||
await build(options) | ||
|
||
options.minify = true | ||
options.outfile = `${outdir}/mqtt.min.js` | ||
await build(options) | ||
|
||
|
||
options.outfile = `${outdir}/mqtt.esm.js` | ||
options.format = 'esm' | ||
|
||
await build(options) | ||
|
||
console.log(`Build time: ${Date.now() - start}ms`) | ||
console.log('Build output:') | ||
|
||
// log generated files with their size in KB | ||
const files = fs.readdirSync(outdir) | ||
for (const file of files) { | ||
const stat = fs.statSync(`${outdir}/${file}`) | ||
console.log(`- ${file} ${Math.round(stat.size / 1024 * 100) / 100} KB`) | ||
} | ||
} | ||
|
||
run().catch((e) => { | ||
console.error(e) | ||
process.exit(1) | ||
}) |
Oops, something went wrong.