GithubHelp home page GithubHelp logo

svelte-custom-element's Introduction

Svelte Custom Element Template

This is a project template for Svelte custom elements. It lives at https://github.com/Dan6erbond/svelte-custom-element-template.

To create a new project based on this template, clone this repository:

git clone https://github.com/Dan6erbond/svelte-custom-element-template.git

Note that you will need to have Node.js and Yarn installed on your machine.

Get Started

  1. Install dependencies:
cd svelte-custom-element-template
yarn
  1. Run the development server:
yarn dev
  1. Open http://localhost:5000 in your browser. You should see a simple page with a "Hello, world!" message and a counter. Edit a component file in src and Rollup's livereload plugin will update the page in the browser.

By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the srv commands in the package.json file to include the option --host 0.0.0.0 or add the option when running the development server.

What's Included

  1. Svelte custom elements with reactivity, slots and CSS.
  2. Nested custom elements to showcase shadow DOM and CSS scoping.
  3. Event emitting and event listening in custom elements and index.html.
  4. Using reserved keywords in Svelte <script> tags.
  5. Helpful code comments to understand the concepts when building Web Components.

Scripts

  • build: Builds the project for production.
  • dev: Runs the development server.
  • start: Starts the production server with built files.
  • check: Runs the Svelte & Typescript code checker.
  • lint: Runs ESLint with the Prettier plugin.
  • format: Runs Prettier.

Building for Production

  1. Run the production build:
yarn build
  1. The built files are in the dist folder.
  2. Include the bundle in your HTML:
<!-- index.html -->
<!DOCTYPE html>
<html>
  <head>
    <title>Svelte Custom Element</title>
    <script src="bundle.js"></script>
  </head>
  <body>
    <my-custom-element></my-custom-element>
  </body>
</html>

Using Typescript

This template is already setup with Typescript. Simply add lang="ts" to your <script> tag to use Typescript or use the .ts extension for your Typescript files.

Contributors

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

svelte-custom-element's People

Contributors

korostelevm avatar

Watchers

 avatar

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.