承接 oblik/kirby-vite 相关项目开发

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

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

oblik/kirby-vite

Composer 安装命令:

composer require oblik/kirby-vite

包简介

Kirby plugin that handles development and production mode of Vite.

关键字:

README 文档

README

Plugin for Kirby that allows you to load assets generated by Vite.

  • In development mode, assets are loaded by Vite's development server, allowing you to benefit from all of its features, such as HMR.
  • In production mode, URLs to the built assets are provided and served by PHP.

Another similar plugin is arnoson/kirby-vite, but it's more complicated and relies on the manual generation of a .lock file (omittable by relying on the manifest's presence solely). Thus, it inspired the creation of this plugin.

Note: Developed and tested with Vite 3.1.2.

How It Works

The plugin depends on Vite's manifest functionality, which generates a manifest.json file that contains a mapping of non-hashed asset filenames to their hashed versions, used by this plugin to render the correct asset links. If this file doesn't exist, it's assumed that Vite is running in development mode and the plugin attempts to request files from Vite's develpment server.

How to Use

Installation

Composer

You can find oblik/kirby-vite on packagist:

composer require oblik/kirby-vite

Download

Download and copy this repository to /site/plugins/vite.

Git Submodule

git submodule add https://github.com/oblik/kirby-vite.git site/plugins/vite

Enable Manifest

Make sure you've enabled the build.manifest option in your vite.config.js:

// vite.config.js
export default defineConfig({
	build: {
		manifest: true,
	},
});

ℹ️ You may want to take a deep dive into Vite's backend integration guide to get an idea how Vite handles assets in traditional backends.

Output JavaScript

You need to pass your entry script to the js() method:

<?= vite()->js('src/index.js') ?>

Output CSS

You have to do the same as for JavaScript, but use the css() method:

<?= vite()->css('src/index.js') ?>

Note: When using Vite, CSS files aare imported in the main JavaScript file. In order to find the CSS from the generated manifest, the plugin needs the file that imports your CSS, not the CSS file itself.

Note 2: In development mode, the css() method does nothing because Vite automatically loads your CSS when your JavaScript loads, as well as the required @vite/client script. In other words, vite()->js() loads everything.

Remove Generated Assets

As explained in the How It Works section, to ensure proper function, you should remove the build folder every time you start your development server. This can easily be done with rm -rf in your npm dev script:

{
	"scripts": {
		"dev": "rm -rf dist && vite"
	}
}

Options

In your config.php, make sure you configure the plugin to match your vite.config.js:

return [
	'oblik.vite' => [
		'server' => [
			'port' => 5173,
			'https' => false,
		],
		'build' => [
			'outDir' => 'dist'
		]
	]
];

Note: The values above are the default ones, so if they match your setup, you don't need to configure anything. 🤙

License

MIT License © 2021-2022 Oblik Studio

统计信息

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

GitHub 信息

  • Stars: 13
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固