Git Product home page Git Product logo

Comments (5)

swyxio avatar swyxio commented on June 23, 2024 2

we have added this as part of svelte recipes svelte-society/recipes-mvp#11

from template.

swyxio avatar swyxio commented on June 23, 2024 1

so i see how u guys apply it with the rollup plugin, but i think for new syntax you need to use preprocessors. example:

<script>
  class Cow {
	// stage 3 class properties syntax
	static sound = "moo";
  }
</script>


<main>
  <h1>Cow says {Cow.sound}!</h1>
</main>

now we need to transpile what's in the script, otherwise acorn throws a fit:

[!] (plugin svelte) ParseError: Unexpected token
src/App.svelte
3:   class Cow {
4:     static sound = "moo";
             ^
5:   }
6: </script>
ParseError: Unexpected token
    at error (/Users/swyx/Desktop/Work/testbed/trybabelrecipe/svelte-app/node_modules/svelte/src/compiler/utils/error.ts:25:16)
    at Parser$1.error (/Users/swyx/Desktop/Work/testbed/trybabelrecipe/svelte-app/node_modules/svelte/src/compiler/parse/index.ts:96:3)
    at Parser$1.acorn_error (/Users/swyx/Desktop/Work/testbed/trybabelrecipe/svelte-app/node_modules/svelte/src/compiler/parse/index.ts:89:8)

So the fix is somewhat different. Make sure @babel/core and the rest of your plugins/presets are installed, then:

// rollup.config.js
// ...

export default {
	// ...
  plugins: [
    svelte({
      // ...
      preprocess: {
        script: ({ content }) => {
          return require("@babel/core").transform(content, {
            plugins: ["@babel/plugin-proposal-class-properties"],
          });
        },
      },
    }),
 // ...

note - i'm honestly not sure if this is slow or suboptimal, i literally just cooked up this example and it worked so 🤷

note - you can also use svelte-preprocess

from template.

ArrowBaZ avatar ArrowBaZ commented on June 23, 2024

Hello @bgreater ,
You can find a example here: https://github.com/jimutt/svelte-pick-a-place/blob/master/rollup.config.js

from template.

eclectic-coding avatar eclectic-coding commented on June 23, 2024

Another option would be to use Parceljs. It is almost a zero configuration bundler. Look at this article to explain the simple setup.
parcel really has become my bundler of choice.

from template.

antony avatar antony commented on June 23, 2024

@bgreater if it's useful - here's how I do it in Sapper https://github.com/antony/sapper-ie

from template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.