svelte-preprocess icon indicating copy to clipboard operation
svelte-preprocess copied to clipboard

Use babel

Open alkorlos opened this issue 5 months ago • 0 comments

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:

  • Your browser and the version: Chrome 121

  • Your operating system: Windows 10 10.0.19045

  • svelte-preprocess version 5.1.3

  • Whether your project uses: Vite and Rollup

Additional context No Additional context.

alkorlos avatar Feb 05 '24 09:02 alkorlos