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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Generated files
dist/
lib/
esm/
flow-typed/

# autoprefixer's eslintConfig was being picked up and attempted to be applied. No thanks
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ node_modules/
.DS_Store

# generated files
lib/
dist/
esm/

# generated site
site/
Expand Down
19 changes: 14 additions & 5 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
{
"dist/react-beautiful-dnd.js": {
"bundled": 362816,
"minified": 135326,
"gzipped": 38147
},
"dist/react-beautiful-dnd.min.js": {
"bundled": 331396,
"minified": 125563,
"gzipped": 35116
},
"dist/react-beautiful-dnd.umd.js": {
"bundled": 362816,
"minified": 135326,
"gzipped": 38147
},
"dist/react-beautiful-dnd.esm.js": {
"bundled": 167329,
"minified": 81581,
"gzipped": 20552,
"treeshaked": {
"rollup": 70346,
"webpack": 71950
}
}
}
16 changes: 6 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.

"module": "dist/react-beautiful-dnd.esm.js",
"sideEffects": false,
"files": [
"/lib",
"/dist",
"/esm",
"/src"
],
"scripts": {
"test": "jest --config ./jest.config.js && cross-env SNAPSHOT=check yarn build:dist",
"validate": "yarn run lint && yarn run typecheck",
"lint": "yarn eslint .",
"typecheck": "flow check",
"build": "yarn run build:clean && yarn run build:lib && yarn run build:esm && yarn run build:flow && yarn run build:dist",
"build:clean": "rimraf lib && rimraf esm && rimraf dist",
"build:lib": "cross-env NODE_ENV=cjs babel src -d lib",
"build:esm": "babel src -d esm",
"build": "yarn run build:clean && yarn run build:dist && yarn run build:flow",
"build:clean": "rimraf dist",
"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.

"storybook": "start-storybook -p 9002",
"build-storybook": "build-storybook -c .storybook -o site",
"prepublish": "yarn run build && cd website && yarn",
Expand Down Expand Up @@ -89,7 +85,7 @@
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-node-resolve": "^3.0.2",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-size-snapshot": "^0.2.1",
"rollup-plugin-size-snapshot": "^0.3.0",
"rollup-plugin-strip": "^1.1.1",
"rollup-plugin-uglify": "^2.0.1",
"styled-components": "^3.2.0"
Expand Down
36 changes: 35 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import replace from 'rollup-plugin-replace';
import strip from 'rollup-plugin-strip';
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';

const pkg = require('./package.json');

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!


const getBabelOptions = () => ({
exclude: 'node_modules/**',
runtimeHelpers: true,
Expand Down Expand Up @@ -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.


{
input,
output: {
file: pkg.main,
format: 'cjs',
},
external: isExternal,
plugins: [
resolve({ extensions }),
babel(getBabelOptions()),
strip({ debugger: true }),
],
},

{
input,
output: {
file: pkg.module,
format: 'es',
},
external: isExternal,
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

sizeSnapshot({ updateSnapshot: !checkSnapshot }),
],
},
];
62 changes: 55 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ acorn-dynamic-import@^2.0.0:
dependencies:
acorn "^4.0.3"

acorn-dynamic-import@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-3.0.0.tgz#901ceee4c7faaef7e07ad2a47e890675da50a278"
dependencies:
acorn "^5.0.0"

acorn-globals@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-4.1.0.tgz#ab716025dbe17c54d3ef81d32ece2b2d99fe2538"
Expand Down Expand Up @@ -2061,6 +2067,10 @@ chownr@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.0.1.tgz#e2a75042a9551908bebd25b8523d5f9769d79181"

chrome-trace-event@^0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/chrome-trace-event/-/chrome-trace-event-0.1.2.tgz#90f36885d5345a50621332f0717b595883d5d982"

ci-info@^1.0.0:
version "1.1.3"
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.1.3.tgz#710193264bb05c77b8c90d02f5aaf22216a667b2"
Expand Down Expand Up @@ -2889,6 +2899,14 @@ enhanced-resolve@^3.4.0:
object-assign "^4.0.1"
tapable "^0.2.7"

enhanced-resolve@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.0.0.tgz#e34a6eaa790f62fccd71d93959f56b2b432db10a"
dependencies:
graceful-fs "^4.1.2"
memory-fs "^0.4.0"
tapable "^1.0.0"

entities@^1.1.1, entities@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0"
Expand Down Expand Up @@ -5272,7 +5290,7 @@ memoize-one@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-3.1.1.tgz#ef609811e3bc28970eac2884eece64d167830d17"

memory-fs@^0.4.0, memory-fs@~0.4.1:
memory-fs@^0.4.0, memory-fs@^0.4.1, memory-fs@~0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552"
dependencies:
Expand Down Expand Up @@ -7098,16 +7116,18 @@ rollup-plugin-replace@^2.0.0:
minimatch "^3.0.2"
rollup-pluginutils "^2.0.1"

rollup-plugin-size-snapshot@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-size-snapshot/-/rollup-plugin-size-snapshot-0.2.1.tgz#f4d95ec11b6b6a291eeb93c87023ed4955942f9c"
rollup-plugin-size-snapshot@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-size-snapshot/-/rollup-plugin-size-snapshot-0.3.0.tgz#ac6e892763828b1618e6545e0252bf9ef5c7c88d"
dependencies:
bytes "^3.0.0"
chalk "^2.3.2"
fast-deep-equal "^1.1.0"
gzip-size "^4.1.0"
jest-diff "^22.4.0"
memory-fs "^0.4.1"
uglify-es "^3.3.9"
webpack "^4.5.0"

rollup-plugin-strip@^1.1.1:
version "1.1.1"
Expand Down Expand Up @@ -7209,7 +7229,7 @@ schema-utils@^0.3.0:
dependencies:
ajv "^5.0.0"

schema-utils@^0.4.0, schema-utils@^0.4.5:
schema-utils@^0.4.0, schema-utils@^0.4.2, schema-utils@^0.4.5:
version "0.4.5"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.4.5.tgz#21836f0608aac17b78f9e3e24daff14a5ca13a3e"
dependencies:
Expand Down Expand Up @@ -7719,6 +7739,10 @@ tapable@^0.2.7:
version "0.2.8"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.8.tgz#99372a5c999bf2df160afc0d74bed4f47948cd22"

tapable@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.0.0.tgz#cbb639d9002eed9c6b5975eb20598d7936f1f9f2"

tar-pack@^3.4.0:
version "3.4.1"
resolved "https://registry.yarnpkg.com/tar-pack/-/tar-pack-3.4.1.tgz#e1dbc03a9b9d3ba07e896ad027317eb679a10a1f"
Expand Down Expand Up @@ -7927,7 +7951,7 @@ uglifyjs-webpack-plugin@^0.4.6:
uglify-js "^2.8.29"
webpack-sources "^1.0.1"

uglifyjs-webpack-plugin@^1.1.6:
uglifyjs-webpack-plugin@^1.1.6, uglifyjs-webpack-plugin@^1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-1.2.4.tgz#5eec941b2e9b8538be0a20fc6eda25b14c7c1043"
dependencies:
Expand Down Expand Up @@ -8151,7 +8175,7 @@ watch@~0.18.0:
exec-sh "^0.2.0"
minimist "^1.2.0"

watchpack@^1.4.0:
watchpack@^1.4.0, watchpack@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.5.0.tgz#231e783af830a22f8966f65c4c4bacc814072eed"
dependencies:
Expand Down Expand Up @@ -8216,6 +8240,30 @@ webpack@^3.10.0:
webpack-sources "^1.0.1"
yargs "^8.0.2"

webpack@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.5.0.tgz#1e6f71e148ead02be265ff2879c9cd6bb30b8848"
dependencies:
acorn "^5.0.0"
acorn-dynamic-import "^3.0.0"
ajv "^6.1.0"
ajv-keywords "^3.1.0"
chrome-trace-event "^0.1.1"
enhanced-resolve "^4.0.0"
eslint-scope "^3.7.1"
loader-runner "^2.3.0"
loader-utils "^1.1.0"
memory-fs "~0.4.1"
micromatch "^3.1.8"
mkdirp "~0.5.0"
neo-async "^2.5.0"
node-libs-browser "^2.0.0"
schema-utils "^0.4.2"
tapable "^1.0.0"
uglifyjs-webpack-plugin "^1.2.4"
watchpack "^1.5.0"
webpack-sources "^1.0.1"

whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-1.0.3.tgz#57c235bc8657e914d24e1a397d3c82daee0a6ba3"
Expand Down