Open compulim opened 3 years ago
Some updates:
We should try something outside of Web Chat, few goals:
As SDK, the problem is uniquely challenged because we want to use ponyfills instead of polyfills.
Updates:
Currently in #4330, we are using ESBuild as development server. We should continue to investigate ESBuild for production build with Babel as the transpilation tool.
Also, we should clean up our exports for better treeshaking.
Background
We bumped to
webpack@5
. Should we move toesbuild
?Let's weight which one is better, in terms of size and speed (for DX).
esbuild
Our bundle must be ES5. But esbuild emit bundle with ES6+. Thus, after esbuild, we need to transpile the bundle again.
esbuild config to use for isomorphic-react
In our
webchat*.js
bundle, although we bundledreact@16.8.6
, if the environment already have awindow.React
andwindow.ReactDOM
object available, we will prefer them over our own bundled React. This is called "isomorphic React".We need to configure esbuild to redirect all
import 'react'
to this isomorphic React package.Content of
esbuild.base.js
Babel config to use on bundle emitted by esbuild
The bundle emitted by esbuild contains many features from ES6+. We need to run Babel again to transpile it back to ES5.
We need to enable a very specific set of plugins. If we enable all plugins via
@babel/preset-env
, it will cause a conflict with Symbol polyfill fromcore-js@3
.Content of
babel.post.config.json
Dependencies
jsonwebtoken
requiresbuffer
. Since we don't verify the token (we merely check theuserId
), we should move tojwt-decode
instead.Investigations
Steps to compile:
@babel/plugin-transform-runtime
and injectcore-js-pure
for usageesbuild
@babel/preset-env
to convert to ES5terser