rocketslab / neewton
InertiaJs 模块管理器。
0.3.2
2021-11-28 02:08 UTC
Requires
- php: ^8.0
- illuminate/console: ^8.0
- illuminate/support: ^8.0
- inertiajs/inertia-laravel: ^0.4.3
Requires (Dev)
- mockery/mockery: ^1.4.4
- phpunit/phpunit: ^9.5.10
README
Neewton 是一个用于 Laravel 应用程序,并集成了 InertiaJs 和 VueJs 的模块管理器。
目的
此项目旨在使 Laravel 应用程序能够通过 InertiaJs 进行模块化,以处理其领域。例如,权限、库存、客户、产品等模块...
每个模块都应该包含管理其中数据状态所必需的组件。我们还可以配置依赖于其他模块的模块,从而确保一个模块可以通过此配置访问另一个模块的数据。
安装
composer require rocketslab/neewton
将资源复制到 Laravel 应用程序中
php artisan neewton:install
如果您系统中没有配置 composer,可以在安装命令中指定其路径
php artisan neewton:install --composer=<caminho para o composer>
配置应用程序以识别模块
客户端
请修改您的 app.js
文件,以便 InertiaJs 能够解析模块。
之前
createInertiaApp(... resolve: import(`./Pages/${name}.vue`).then(module => module.default) ...)
之后
import neewton from './neewton'; createInertiaApp(... resolve: name => neewton(name), ...)
Laravel Mix
请确保您的 webpack.mix.js
调用了 vue()
方法。这是必需的,以便 Laravel Mix/Webpack 能够找到并编译应用程序和模块的 .vue
文件。
webpack.mix.js
mix.js('resources/js/app.js', 'public/js') .vue() // <<<<< == adicione esta linha ... // demais plugins/funções (se houver)
服务器端
Neewton 注册了一个 Blade 标签 @neewtonModules
,以便定位和配置模块。
请将此标签添加到 app.blade.php
文件或您自己的布局文件中,紧接在 <script src="{{ mix('js/app.js') }}" defer></script>
下方。
app.blade.php
... <!-- Active neewton modules --> @neewtonModules ...
这需要在第一次安装和每次修改模块(添加或删除)时清理视图缓存,并重新编译项目/模块的资产。
php artisan view:clear && npm run [dev|prod]
配置
要添加或删除模块,请发布 Neewton 的配置文件。
php artisan vendor:publish --provider="RocketsLab\Neewton\NeewtonServiceProvider"
要添加模块,只需将配置模块的类添加到 config/neewton.php
中的 active_modules
数组中。
示例
<?php return [ /* * Active modules array, put here each module registration class */ 'active_modules' => [ Module\\Exemplo\\Register::class ] ];
创建模块的文档将在这里提供
®2021 Jorge @jjsquady Junior