Replies: 2 comments
-
There used to be a /**
* @typedef {import("@swc/core").JscTarget} EcmaVersion
*/
import {transform} from '@swc/core';
import {readdirSync as dir, readFileSync as read, writeFileSync as write} from 'fs';
import {join, parse} from 'path';
/**
* @param {string} directory
* @param {EcmaVersion} ecmaVersion
*/
async function build(directory, ecmaVersion='es5') {
let files = dir(directory, {recursive: true}).filter(file => {
return file.match(/\.js$/i);
}).map(file => join(directory, file));
for (let file of files) {
let name = parse(file).base;
let source = read(file, 'utf-8');
let compiled = await transform(source, {
filename: name,
jsc: {
target: ecmaVersion,
parser: {
syntax: 'ecmascript',
},
transform: {},
},
});
write(file, compiled.code);
}
} And then you could transform an entire directory of files, like this: build('src', 'es5'); //if your files are in the `src` directory Note: This script I have provided is rather minimal and doesn't account for things like error handling. |
Beta Was this translation helpful? Give feedback.
-
ES5 does not have lots of features we rely on, so beyond downleveling syntax you would also need a bunch of polyfills. Most notably, Svelte 5 uses proxies, which AFAIK are not really polyfillable. Converting this to a discussion because this is neither a feature request (or rather; we won't add such an option) nor a bug report. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the problem
I want to use Svelte on a browser that only has ECMAScript 5.1 support.
The aim is to use the current Vite build system with minimal playing around.
I know that in the past, rollup was used directly which meant you could do a whole lot of playing around with configs and use a ECMAScript 5.1 conversion plugin.
Describe the proposed solution
Is there a flag I can use to change the output?
Importance
It would be great since I'm not a JS developer and playing with configs intimidates me.
Beta Was this translation helpful? Give feedback.
All reactions