sevenwestmedia-labs / node-knex-query-executor

TypeScript first encapsulation and reusability of knex database queries
MIT License
3 stars 4 forks source link

build: Enabled esm and es2015 builds #9

Closed JakeGinnivan closed 5 years ago

JakeGinnivan commented 5 years ago

See http://2ality.com/2017/04/setting-up-multi-platform-packages.html

andyjdavis commented 5 years ago

I'm not 100% sure I understand the objective of this PR. Does this cause this module to be available in multiple different formats?

If so can you provide an example of how a specific format would be consumed?

JakeGinnivan commented 5 years ago

Yep sure! Here is a breakdown

"main": "dist/cjs/index.js",

Main is what 'node' will use to resolve what file it needs to include, node doesn't understand es2015 imports (the import / export keywords) so we need a plain commonJS build.

"module": "dist/esm/index.js",

Module is what webpack will use to resolve what to include. Webpack can statically analyse import/export statements for tree shaking. You can't tree shake common js format, which node understands.

"sideEffects": false,

By default webpack assumes that importing modules has side effects, so it cannot tree shake (remove any exports which are not imported in your code). By marking the package as sideEffects: false webpack will be able to tree shake this module resulting in smaller bundle size. This package it doesn't matter too much because it doesn't end up in the browser, but I am doing this setup across everything for consistency.

andyjdavis commented 5 years ago

I see. Seems more important in the client side code but happy to see consistency.

JakeGinnivan commented 5 years ago

:tada: This PR is included in version 2.0.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: