• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    Elixir
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Elixir Phoenix + Svelte = ❤️

Sveltex

Building web using Phoenix is fun. Creating component using Svelte is fun.

Imagine we can just create svelte component, save it as component_name.svelte inside our /assets/js/svelte and anytime we need it inside our layout, we can just call it like so:

<%= Sveltex.render "component_name", %{props_as_map: ""} %>

Sveltex does exactly this.

Install in 4 easy step.

This library works well with Phoenix 1.4.12 and above. (Last time tested with Phoenix 1.5.9)

If available in Hex, the package can be installed by adding sveltex to your list of dependencies in mix.exs:

  1. Install Sveltex as Elixir dependency.

    Add the dependency into your mix.exs

        def deps do
          [
            {:sveltex, git: "https://github.com/virkillz/sveltex.git", tag: "1.1.2"}
          ]
        end`

    Then run:

    mix deps.get
    
  2. Install Svelte & Svelte Loader as Javascript dependency

 cd assets && npm install svelte svelte-loader --save
  1. Edit your Webpack config file /assets/webpack.config.js

    Add resolve:

      module.exports = (env, options) => ({
    
      resolve: {
        alias: {
          svelte: path.resolve('node_modules', 'svelte')
        },
        extensions: ['.mjs', '.js', '.svelte'],
        mainFields: ['svelte', 'browser', 'module', 'main'],
        modules: ['node_modules']
      },

    And add 2 new rules under module rules

        module: {
          rules: [
            {
              test: /\.mjs$/,
              include: /node_modules/,
              type: 'javascript/auto',
            },
            {
              test: /\.(html|svelte)$/,
              exclude: /node_modules/,
              use: {
                loader: 'svelte-loader',
                options: {
                  hotReload: true
                }
              }
            }
          ]
        }
      });
  2. Import to your app.js (/assets/js/app.js file).

 import "../../deps/sveltex/assets/sveltex.js";

How to use ?

Put your svelte component files (.svelte) under /assets/js/svelte directory.

Example: test.svelte

<script>
  export let name;
</script>

<h1>Hey {name}, Phoenix and Svelte setup is working!</h1>

Then anywhere in your view template you can use

<%= Sveltex.render "test", %{name: "virkillz"} %>

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/sveltex.

More Repositories

1

tailstack

Drag and drop tailwind component
JavaScript
25
star
2

phoenixadmin

Better admin panel and HTML generator for Phoenix. 1.3
JavaScript
10
star
3

php-price-crawler

codeigniter based price crawler using Xpath to crawl ecommerce data.
PHP
9
star
4

erc20_payment_gateway

Whole payment gateway service for ERC20, currently set for IDK.
CSS
6
star
5

tailupgrade

Small utility to convert .html files with tailwind v.0.x class name into compatible with version v.1.0
JavaScript
6
star
6

hash_color_avatar_elixir

Create SVG avatar with initial and pretty hash color!
Elixir
4
star
7

phoenix_admin_1_4

Phoenix admin boilerplate for Phoenix 1.4, better template + auth
Elixir
3
star
8

elixir_rss

ElixirRss is a simple feed parser originally meant to parse the feed from crypto news. It parse more information including images.
Elixir
3
star
9

avatar-api

Source for avatar-api.org
CSS
2
star
10

phoenix-spark

Web application boilerplate with user and admin login for Phoenix Framework.
CSS
2
star
11

monitrage

Crypto exchange scanner to find profitable arbitrage potential
Elixir
2
star
12

generate-bulk-eth-address

simple nodejs script to generate ethereum address and private keys
JavaScript
2
star
13

multichain-elixir

Blockchain made easy. Wrapper for Multichain JSON RPC API for Elixir.
Elixir
2
star
14

stuckwithyou

Chat with random stranger, omegle/chatroullette style chat application, built with firebase and ionic framework.
TypeScript
2
star
15

controlled_token

Solidity contract to mimick stable coin feature.
JavaScript
1
star
16

awesome-stuff

my personal awesome list
CSS
1
star
17

midtrans

Elixir library for midtrans payment gateway integration
Elixir
1
star
18

indodax

Indodax Trading API wrapper in Elixir
Elixir
1
star
19

kudo

sanbox cryptocurrency api
Python
1
star
20

tokex

Tokenomy Crypto Exchange API Library in Elixir
Elixir
1
star
21

portafolio

Pet Project. Ignore it.
CSS
1
star
22

ethermass

Bulk transaction manager with GUI for Ethereum network.
Elixir
1
star
23

vkadmin

Just another phoenix admin boilerplate
JavaScript
1
star
24

cryptomonitor

Crypto arbitrage app using Elixir, Elm, Phoenix.
CSS
1
star
25

tailerplate2

Tailerplate version 2. Now with zurb panini and gulp
CSS
1
star
26

tailwind-elm-boilerplate

Just quick boilerplate of Elm using tailwind.
CSS
1
star
27

tsert

CLI tool to insert html snippet hosted in my github repo and insert into given html file.
JavaScript
1
star