定制 k10r/vite-encore 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

k10r/vite-encore

Composer 安装命令:

composer require k10r/vite-encore

包简介

Webpack encore like entrypoint loader for ViteJS

README 文档

README

This Symfony bundle assists with the integration of Vite by providing Twig functions to render assets based on Vite's manifest.json or its dev server.

Requirements

In order to use this bundle, your project has to fulfill the following requirements:

  • Symfony ^4.4 || ^5.0 || ^6.0

Installation

Install the bundle by running:

composer require k10r/vite-encore

Now, register the bundle in your config/bundles.php:

return [
    // ...
    K10r\ViteEncoreBundle\K10rViteEncoreBundle::class => ['all' => true],
];

If you have not installed Vite, yet, do so by running:

npm install -D vite

Configuration

Configuring the bundle consists of two parts: Vite and Symfony. The latter part is optional, since this bundle already provides reasonable defaults.

Vite

Start by creating a vite.config.js file inside your project's root directory and populate it with the following content:

import { defineConfig } from 'vite';
import { resolve } from 'path';

export default defineConfig({
    root: 'assets',
    base: '/dist/',

    build: {
        outDir: resolve(__dirname, 'public/dist'),
        emptyOutDir: true,
        manifest: true,
        target: 'es2018',
        rollupOptions: {
            input: '/js/app.js'
        },
    },

    server: {
        cors: true,
        strictPort: true,
        port: 3000,
    },
});

From there on, you can adjust the configuration as you see fit. For more information on how to configure Vite, see the official documentation.

To make the above configuration work with your project, you want to create an app.js inside the <project-root>/assets/js directory or adjust the root and build.rollupOptions.input options inside the config.

Symfony

In order to change the default configuration, a k10r_vite_encore.yaml can be created inside the <project-root>/config/packages directory.

The default configuration is as follows:

# config/packages/k10r_vite_encore.yaml
k10r_vite_encore:
    base: /dist/
    server:
        enabled: true
        host: localhost
        port: 3000
        https: false

Options

base - string

This option tells Symfony where to find the bundled assets, relative to the public directory. The value has to be equal to the root option inside the Vite config, as well as match the final path fragment of the build.outDir option.

server.enabled - bool

This option controls, if the Vite dev server should be used, when the project is launched with APP_ENV=dev. This requires the development server to be started.

server.host - string

This options controls, which hostname is used to query assets from the development server. It should correspond to the IP/hostname on which the development server will be running.

server.port - int

This option controls, which port is used to access the development server. It should correspond to the server.port option from the Vite configuration.

server.https - bool

This options controls, if the development server should be accessed via https.

Usage

In order to include your bundled assets, use the following Twig functions for scripts and styles respectively:

{{ vite_style_entry('js/app.js') }}
{{ vite_script_entry('js/app.js') }}

The js/app.js is the entrypoint corresponding to the Vite configuration provided above. It as to correspond to the build.rollupOptions.input value without trailing slashes.

Using the development server

You can launch the development server by running npx vite or creating an alias script inside your package.json to run vite.

Building for production

If you want to build for production, use the command npx vite build or do so by creating an alias script inside your package.json to execute vite build.

Changelog

This project adheres to Semantic Versioning. Please refer to the CHANGELOG.md for detailed changes and migration instructions.

License

MIT

k10r/vite-encore 适用场景与选型建议

k10r/vite-encore 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 549 次下载、GitHub Stars 达 9, 最近一次更新时间为 2021 年 10 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 k10r/vite-encore 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 549
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-14