Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide cjs and esm bundles with information about treeshakability #429

Merged
merged 4 commits into from
Apr 10, 2018
Merged

Provide cjs and esm bundles with information about treeshakability #429

merged 4 commits into from
Apr 10, 2018

Conversation

TrySound
Copy link
Contributor

@TrySound TrySound commented Apr 9, 2018

Ref #405
Closes #428

Copy link
Collaborator

@alexreardon alexreardon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not my area of expertise. Can you please elaborate on the motivations behind this change and the benefits of it?

Thanks for seeking to improve our builds @TrySound 👏

@@ -15,26 +15,22 @@
"bugs": {
"url": "https://github.com/atlassian/react-beautiful-dnd/issues"
},
"main": "lib/index.js",
"module": "esm/index.js",
"main": "dist/react-beautiful-dnd.cjs.js",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it common to do this rather than use a seperate folder?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dumb question, but cjs = CommonJS? 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not necessary to create a folder for only one file in it. We have five file in the end which look very nice in one folder.

Yes, esm and cjs are the most popular shorthands.

"build:dist": "rollup -c",
"build:flow": "echo \"// @flow\n\nexport * from '../src';\" | tee lib/index.js.flow esm/index.js.flow",
"build:flow": "echo \"// @flow\n\nexport * from '../src';\" > dist/react-beautiful-dnd.cjs.js.flow",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is flow okay with this? Do we want it also for the .esm.js file too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary. Users usually do not specify esm entry directly, but rely on bundler.

rollup.config.js Outdated
@@ -47,6 +51,36 @@ const getUMDConfig = ({ env, file }) => {
};

export default [
getUMDConfig({ env: 'development', file: 'dist/react-beautiful-dnd.js' }),
getUMDConfig({ env: 'development', file: 'dist/react-beautiful-dnd.umd.js' }),

getUMDConfig({ env: 'production', file: 'dist/react-beautiful-dnd.min.js' }),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.umd.min.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break pattern :(

react-beautiful-dnd.cjs.js
react-beautiful-dnd.cjs.js.flow
react-beautiful-dnd.esm.js
react-beautiful-dnd.min.js
react-beautiful-dnd.umd.js

I just would like to see this pattern widespread, so min in most cases could mean umd format. I already used it in a set of modules.

@TrySound
Copy link
Contributor Author

TrySound commented Apr 9, 2018

There are a few benefits

  1. Preventing user from importing internals. I saw it a lot, so packages couldn't change their structure to not break these users. It's better to have only one API definition via only named imports without dependency on file structure.
  2. Better control of own code size. Currently we can see the size with reusable dependencies.
  3. Control of treeshakability. Not sure how much it is relevant to this package.

@alexreardon
Copy link
Collaborator

Can you please elaborate on:

Preventing user from importing internals.

@TrySound
Copy link
Contributor Author

TrySound commented Apr 9, 2018

Users may use some internals with import something from 'react-beautiful-dnd/dist/something.js'. It's usually a private code, which should not be considered as public API. Bundle allows to isolate such private code in single module scope, so users won't have an access to it and won't be broken when file structure is changed.

@alexreardon
Copy link
Collaborator

Perfect. Thanks

rollup.config.js Outdated
const input = './src/index.js';

const extensions = ['.js', '.jsx'];

const isExternal = id => !id.startsWith('.') && !id.startsWith('/');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add a comment above this line in the code explaining its purpose? Other than that I think I am good to go!

rollup.config.js Outdated
plugins: [
resolve({ extensions }),
babel(getBabelOptions()),
strip({ debugger: true }),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am keen to keep console.* statements for the non-minified builds. Can the strip function be updated so that only the minified build strips console.*? https://github.com/rollup/rollup-plugin-strip#usage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From non minified umd too? It seems console was always stripped from both umd bundles

@alexreardon
Copy link
Collaborator

alexreardon commented Apr 10, 2018 via email

@TrySound
Copy link
Contributor Author

Done

@alexreardon
Copy link
Collaborator

Well done @TrySound. Thanks for your efforts in getting this in!

@alexreardon alexreardon merged commit 54708dc into atlassian:master Apr 10, 2018
@TrySound TrySound deleted the cjs-and-esm-bundles branch April 10, 2018 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants