Skip to content

Conversation

nstepien
Copy link
Collaborator

@nstepien nstepien commented Nov 7, 2020

Pros:

  • Babel's output is better and less buggy than TS's.
  • Can publish with the new React runtime sooner.
  • More flexibility, can use fancy babel/rollup plugins:
  • Smaller npm footprint:
    • No mixed bundles/modules+sourcemaps in published files.
    • Code that's not exported or unused by exports will be tree-shaken.

We still use tsc to output declaration files.

@nstepien nstepien self-assigned this Nov 7, 2020
'@typescript-eslint/consistent-type-assertions': [2, { assertionStyle: 'as', objectLiteralTypeAssertions: 'never' }],
'@typescript-eslint/consistent-type-definitions': [1, 'interface'],
'@typescript-eslint/consistent-type-imports': [1, { prefer: 'no-type-imports' }],
'@typescript-eslint/consistent-type-imports': 1,
Copy link
Collaborator Author

@nstepien nstepien Nov 7, 2020

Choose a reason for hiding this comment

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

I've tweaked this so we'll now use type imports, this is to help babel elide type imports, otherwise it cannot always know to remove some imports, especially in files like src/index.ts.

Comment on lines +9 to +10
"@babel/proposal-nullish-coalescing-operator",
"@babel/proposal-optional-chaining"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fun fact: with our browserslist config, and our code, aside from these two transform plugins, @babel/preset-env does nothing.

"@babel/proposal-optional-chaining"
]
}],
["@babel/react", { "useSpread": true }],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll change this to use the new runtime in #2184

"@babel/typescript"
],
"plugins": [
["@babel/transform-runtime", { "useESModules": true }],
Copy link
Collaborator Author

@nstepien nstepien Nov 7, 2020

Choose a reason for hiding this comment

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

We might have to add @babel/runtime in our dependencies in the future, but currently no helpers get imported in our bundles.
useESModules should also be set to false for the cjs bundle.

'react',
'react-dom'
],
external: id => !id.startsWith('.') && !isAbsolute(id),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will mark all non-relative imports as external, in other words all npm dependencies.

@nstepien nstepien marked this pull request as ready for review November 7, 2020 17:25
@nstepien nstepien requested a review from amanmahajan7 November 7, 2020 17:25
Copy link
Collaborator

@amanmahajan7 amanmahajan7 left a comment

Choose a reason for hiding this comment

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

A few questions. LGTM

{
"presets": [
["@babel/env", {
"loose": true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we be using loose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Original code:

ref.current?.focus({ preventScroll: true });

With loose enabled:

(_ref$current = ref.current) == null ? void 0 : _ref$current.focus({

With loose disabled:

(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus({

In non-loose mode, the value is explicitely checked for both null and undefined, as it needs to work with document.all, but we don't use document.all anywhere so it's safe.
image

It might matter in the future for new js syntax features, but loose will only break edge cases so I think it's fine.

{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this if we have noEmit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes unfortunately.

> react-data-grid@7.0.0-canary.30 typecheck
> tsc -p tsconfig.all.json

tsconfig.all.json:4:5 - error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit'.

4     "noEmit": true
      ~~~~~~~~


Found 1 error.

nodeResolve()
babel({
babelHelpers: 'runtime',
skipPreflightCheck: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if it is worth enabling it? Does it slow down the build by much?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It builds in 1s in both cases, but I ran into issues before so I had to add this. I'll remove it now.

@nstepien nstepien merged commit 7b015eb into canary Nov 9, 2020
@nstepien nstepien deleted the babundle branch November 9, 2020 20:18
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