arbims / vite-plugin
为 CakePHP 定制的 VitePlugin 插件
v1.0.3
2024-05-28 08:14 UTC
Requires
- php: >=7.4
- cakephp/cakephp: ^5.0.1
Requires (Dev)
- phpunit/phpunit: ^8.5 || ^9.3
README
安装
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方式是
composer require arbims/vite-plugin
在 Application.php 中加载插件
bin/cake plugin load VitePlugin
在 AppView.php 中加载 Helper
$this->loadHelper('VitePlugin.Vite');
在 /config/bootstrap.php 中添加 Vite 环境配置
Configure::write('IS_DEV', true);
用法
运行以下命令
如果您想使用 vue 替换 react 或 preact
bin/cake vite_plugin react
在您的 php-layout 中,在 html head 中包含以下内容
<?= $this->Vite->assets('js/main.jsx', \Cake\Core\Configure::read('IS_DEV'), 'react') ?>
如果您想使用 vue
<?= $this->Vite->assets('js/main.js', \Cake\Core\Configure::read('IS_DEV')) ?>
然后运行
npm install
npm install -D sass
npm run dev
如果我们处于生产环境,需要将 IS_DEV 变量改为 false。
Configure::write('IS_DEV', false);
然后运行
npm run build