承接 wewowweb/laravel-svelte-preset 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wewowweb/laravel-svelte-preset

Composer 安装命令:

composer require wewowweb/laravel-svelte-preset

包简介

Svelte frontend preset for Laravel.

README 文档

README

A Laravel frontend preset for initial Svelte scaffolding.

Why?

Svelte is an interesting new approach in the JavaScript space, created by @Rich_Harris. While traditional frontend frameworks do the bulk of their work in the browser, Svelte does this in compilation step. They provide a fluid syntax for writing expressive code, but compile it down to small, framework-less vanilla JavaScript.

If you don't know what Svelte is, we highly recommend starting with Rich Harris' talk Rethinking Reactivity from YGLF Code Camp 2019, his introductory blog post or - if you're more of a hands-on type - Svelte's interactive tutorial.

This package is still in active development, so you might want to watch the repository to be notified of future changes.

Installation

You can install the package via composer:

composer require wewowweb/laravel-svelte-preset

After that, run the following command, which will provide you with the initial scaffolding of the project:

php artisan ui svelte

To install the JavaScript dependencies, run:

npm install && npm run dev

The package will provide you with the initial set of files:

  • /js/app.js
  • /js/components/App.svelte
  • webpack.mix.js

needed to start developing with Laravel & Svelte.

Usage

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
  <head>
    ...
    <!-- Include the app.js file -->
    <script src="{{ mix('js/app.js') }}" defer></script>
  </head>
  <body>
    <!-- Include your App Component -->
    <App />
  </body>
</html>

Registering Custom Svelte Components

If you wish to use custom components, note you cannot use regular svelte components. Doing so will result in an invalid constructor error for the svelte component.

Please follow these general conventions when creating your custom components:

  • Component name must be two or more words joined by the '-' character e.g. 'my-test-component'.
  • Components can be accessed in blade file like a regular html tag e.g. <my-test-component></my-test-component>
  • Closing tag is necessary because its a web component.

If you wish to register a custom component and use it within your blade.php files, you can do it like so:

Step 1: Create a New Custom Component

Let's create a new Svelte Component (e.g. MyTestComponent.svelte)

<script></script>

<main>
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-md-8">
        <div class="card">
          <div class="card-header">My Test Component</div>
          <div class="card-body">
            I'm a test component.
          </div>
        </div>
      </div>
    </div>
  </div>
</main>

Step 2: Modify The webpack.mix.jsfile

Modifiy the webpack.mix.js file like so:

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
-   .svelte();
+   .svelte({
+       customElement: true,
+       tag: null // to get rid of "no custom element tag name" warning because we are defining components tag name it in app.js file. otherwise you would have to put "<svelte:options tag={null} />" in all of your custom elements.
+   });

Step 3: Import the component to your app.js

Then within your àpp.js file, import the MyTestComponent like so:

require('./bootstrap');

import App from "./components/App.svelte";
+ import MyTestComponent from "./components/MyTestComponent.svelte";

const app = new App({
  target: document.body
});

window.app = app;

+ customElements.define('my-test-component', MyTestComponent);
export default app;

Step 4: Convert your App component to a custom component

require('./bootstrap');

import App from './components/App.svelte';
import MyTestComponent from './components/MyTestComponent.svelte';

+ customElements.define('my-app', App);
customElements.define('my-test-component', MyTestComponent);

- const app = new App({
-     target: document.body,
- });

- window.app = app;
- export default app;

Step 5: Use the new component in your blade.phpfile

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        ...
        <!-- Include the app.js file -->
        <script src="{{ mix('js/app.js') }}" defer></script>
    </head>
    <body>
        <!-- Include your App Component -->
-       <App />
+       <my-app></my-app>
+       <my-test-component></my-test-component>
    </body>
</html>

Additionally, you may also define the tag within your svelte component instead of with customElement.define as so:

<svelte:options tag="my-test-component" />

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email gal@wewowweb.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

wewowweb/laravel-svelte-preset 适用场景与选型建议

wewowweb/laravel-svelte-preset 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.21k 次下载、GitHub Stars 达 74, 最近一次更新时间为 2019 年 05 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「We Wow Web」 「svelte」 「laravel-svelte-preset」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 wewowweb/laravel-svelte-preset 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 wewowweb/laravel-svelte-preset 我们能提供哪些服务?
定制开发 / 二次开发

基于 wewowweb/laravel-svelte-preset 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7.21k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 74
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 74
  • Watchers: 13
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-21