chialab / rna-cakephp
一个 CakePHP 插件,可以无缝集成 @chialab/rna 构建工件。
v0.3.0
2023-07-11 06:35 UTC
Requires
- php: >=7.4
- ext-json: *
- cakephp/cakephp: ^4.2
Requires (Dev)
- cakephp/cakephp-codesniffer: ~4.2.0
- phpunit/phpunit: ~8.5.0 || ^9.3
README
CakePHP 插件,用于无缝集成 CakePHP 和 @chialab/rna 构建工件。
安装
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方式是
composer require chialab/rna-cakephp
您必须通过在应用程序类的 bootstrap
方法中加载插件来将插件加载到您的 CakePHP 应用程序中
class Application extends \Cake\Http\BaseApplication { public function bootstrap(): void { parent::bootstrap(); // ... $this->addPlugin('Chialab/Rna'); } }
使用方法
RNA Helper
在视图类中加载该辅助器
class View extends \Cake\View\View { public function initialize(): void { parent::initialize(); // ... $this->loadHelper('Chialab/Rna.Rna'); } }
然后在模板中使用它
-
注入由开发服务器生成的代码(仅在
debug
开启时){{ Rna.devServer()|raw }} {{ Rna.devServer('YourPlugin')|raw }}
-
加载资源
{{ Rna.script('index')|raw }} {{ Rna.css('YourPlugin.main')|raw }} {{ Rna.script('YourPlugin.main', { type: 'module' })|raw }}
从 Symfony Encore 迁移
按照以下说明从基于 Webpack Encore 的配置迁移
- 在您项目的根目录中创建一个
rna.config.js
文件。 - 定义入口点
/** * @param {import('@chialab/rna-config-loader').Config} config * @param {import('@chialab/rna-config-loader').Mode} mode */ export default function(config, mode) { return { ...config, entrypoints: [ // Encore.addEntry('section-filters', `./resources/js/section-filters.js`) { input: [ './resources/js/section-filters.js', ], output: '/webroot/build', }, // Encore.addEntry('app', './resources/js/app.js').addStyleEntry('app-style'', './resources/css/app.css') // Encore.script('app') -> Rna.script('app') // Encore.css('app-style') -> Rna.css('app') { input: [ './resources/js/app.js', './resources/js/app.css', ], output: '/webroot/build', }, ], }; }
- 扩展 RNA 配置
export default function(config, mode) { return { ...config, entrypoints: [...], // Encore.cleanupOutputBeforeBuild() clean: true, // Encore.enableSourceMaps(!Encore.isProduction()) minify: mode === 'build', sourcemap: mode !== 'build', // Encore.enableVersioning(Encore.isProduction()) entryNames: mode === 'build' ? '[name]-[hash]' : '[name]', chunkNames: mode === 'build' ? '[name]-[hash]' : '[name]', assetNames: mode === 'build' ? 'assets/[name]-[hash]' : '[name]', // Encore.setPublicPath('/webroot/build') manifestPath: 'webroot/build/manifest.json', entrypointsPath: 'webroot/build/entrypoints.json', }; }
- 移除
@symfony/webpack-encore
、webpack
和 webpack 加载器