Preprocessor for blocks of Python in Svelte templates (using Vite and Transcrypt)
npm install vite-svelte-transcrypt[proof of concept] Preprocessor for blocks of Python in Svelte templates (using Vite and Transcrypt)
``bash`
pip install transcrypt
npm install --save vite-svelte-transcrypt
`ts
// example vite.config.js or vite.config.ts
import {defineConfig} from 'vite'
import {svelte} from '@sveltejs/vite-plugin-svelte'
import sveltePreprocess from 'svelte-preprocess';
import {python} from "vite-svelte-transcrypt"; // <-
// https://vitejs.dev/config/
export default defineConfig({
plugins: [svelte({
preprocess: sveltePreprocess({
aliases: [ // register lang="python" and .py files as Python
['py', 'python'],
['python', 'python'],
],
python // <-
}),
})],
})
`
`sveltehtml
count = 0
def increment():
count += 1
`
Note: the backticks (` ``) are not required, but can improve Language Injection features of some editors (i.e. you
can tell Pycharm the 'string' is supposed to be Python.)
You also have access to all Javascript globals. In order to prevent the editor from complaining it doesn't know these,
you can use the global keyword:
`sveltehtml
``
This whole project is just a proof of concept and should NOT be used in production!
The whole Transcrypt JS runtime is included for every
``