Converting code to ES5
Hello! I need to convert my code to ES5 format and I faced such a problem that const and let variables remain in the assembled project, I expected that all variables will be converted to var, but this did not happen.
This is what the assembled project looks like (1 image), I'm not sure, but almost all const and let variables were created by SolidJS
This is what my Babel Loader looks like:
const babelLoader = {
test: /.(js|jsx|ts|tsx)$/,
exclude: [options.paths.corejs],
use: {
loader: 'babel-loader',
options: {
babelrc: false,
configFile: false,
sourceType: 'unambiguous',
presets: [
[
'@babel/preset-env',
{
targets: {
samsung: '4',
},
useBuiltIns: 'usage',
corejs: '3.27',
},
],
'solid',
'@babel/preset-typescript',
],
plugins: getBabelPlugins(options.isDev),
},
},
};
getBabelPlugins(options.isDev) returns:
[
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-block-scoping'
]
My main question comes up is how can I convert const variables and let them into var within SolidJS itself? P.S. I need this because I have to support 2013 browsers. I will be glad for any hint, thanks for your attention π
10 Replies
I'm not so strong at Babel, but if you use typescript you can set the target to es5, and that does remove the let/const
I'm curious for your use case because tbh I really don't see why you need es5
Can you please elaborate on what target you are talking about?
@seventimes https://www.typescriptlang.org/tsconfig#target
TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
I mean why do you need to polyfill es6 ?
I need this because I need to support very old TVs, unfortunately you canβt update the browser on them
ok interesting makes sense then. It's just that in 2023 there really is no need to polyfill es6 for normal usage
Unfortunately :(, this did not help me, I think that the problem appears at the moment when the "jsxTransform" occurs and it just creates all these const and let variables
GitHub
plugins/presets order Β· Issue #4882 Β· babel/babel
In documentation it is written: Plugins run before Presets. Plugin ordering is first to last. Preset ordering is reversed (last to first). I wrote my own plugin which works with const and let. It w...
sometimes it can happen. for example for apps I develop at work in our organization there are very old machines. some running win XP and no way to install latest browsers there. though (with firefox) they support part of modern JS api, like
let
and Map
, Set
but it thowed me errors for something I made with Vue (I guess shadowRoot
. I just defined some object to window to suppress those. because none of my components use that feature, it is just Vue internals have checks)