sveltejs / svelte-preprocess

A ✨ magical ✨ Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, Coffeescript, TypeScript, Pug and much more.
MIT License
1.73k stars 147 forks source link

Use babel #625

Open alkorlos opened 4 months ago

alkorlos commented 4 months ago

Hello! Thank you for functional library!

Describe the bug Need to use babel, the example from the documentation is not working, and I can't figure out why.

Testing on @babel/plugin-transform-unicode-sets-regex src\App.svelte:

<script>
 <!-- ... -->

  const re = new RegExp("/[\p{ASCII}&&\p{Decimal_Number}]/v")
  console.log(re)
</script>

In the dist\assets\index-name.js expecting

/[0-9]/u

But there is no transpilation happening.

Logs No Logs with error.

To Reproduce svelte-preprocess-issue-babel

Doing this: npm create vite@latest, options: Svelte, JavaScript npm install svelte-preprocess @babel/core @babel/preset-env --save Update svelte.config.js:

import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
import preprocess from 'svelte-preprocess'

export default {
  preprocess: [
    vitePreprocess(),
    preprocess({
      babel: {
        presets: [
          [
            '@babel/preset-env',
            {
              loose: true,
              modules: false,
              targets: {
                esmodules: true,
              },
            },
          ],
        ],
      },
    })
  ],
}

That's all.

Did I miss a step in the documentation?

Expected behavior Expected transpilation JS.

Stacktraces No Stacktraces.

Information about your project:

Additional context No Additional context.