-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: use esbuild for nodejs bundle
- Loading branch information
1 parent
af0f3f1
commit 7c00f59
Showing
3 changed files
with
79 additions
and
64 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
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,61 @@ | ||
const banner = require('../../src/fragments/license'); | ||
const umdWrapper = require('esbuild-plugin-umd-wrapper'); | ||
const stripLogsPlugin = require('./strip-logs').default; | ||
|
||
// We need to create a new copy of the base config each time, because calling | ||
// esbuild.build() with the base config causes it to mutate the passed | ||
// config’s `banner.js` property to add some weird modules shim code, | ||
// which we don’t want here. | ||
function createBaseConfig() { | ||
return { | ||
bundle: true, | ||
sourcemap: true, | ||
format: 'umd', | ||
banner: { js: '/*' + banner + '*/' }, | ||
plugins: [umdWrapper.default({ libraryName: 'Ably', amdNamedModule: false })], | ||
target: 'es2017', | ||
}; | ||
} | ||
|
||
const webConfig = { | ||
...createBaseConfig(), | ||
entryPoints: ['src/platform/web/index.ts'], | ||
outfile: 'build/ably.js', | ||
}; | ||
|
||
const minifiedWebConfig = { | ||
...createBaseConfig(), | ||
outfile: 'build/ably.min.js', | ||
minify: true, | ||
}; | ||
|
||
const modularConfig = { | ||
...createBaseConfig(), | ||
entryPoints: ['src/platform/web/modular.ts'], | ||
outfile: 'build/modular/index.js', | ||
format: 'esm', | ||
plugins: [stripLogsPlugin], | ||
}; | ||
|
||
const nodeConfig = { | ||
...createBaseConfig(), | ||
platform: 'node', | ||
entryPoints: ['src/platform/nodejs/index.ts'], | ||
outfile: 'build/ably-node.js', | ||
/* | ||
* in order to support both named, and default exports in commonjs, esbuild | ||
* will export named exports by name on module.exports and default exports on | ||
* module.exports.default. Since we export everything on the default export | ||
* object anyway, we can just ignore named exports and only export the default. | ||
* Without this footer, you would need to require('ably').default.Realtime to | ||
* access client constructors. | ||
*/ | ||
footer: { js: 'module.exports = module.exports.default;' }, | ||
}; | ||
|
||
module.exports = { | ||
webConfig, | ||
minifiedWebConfig, | ||
modularConfig, | ||
nodeConfig, | ||
}; |
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