hshn / npm-bundle
此包已被废弃,不再维护。未建议替代包。
使用 npm 处理资产依赖和脚本
v0.3.0
2017-08-31 04:46 UTC
Requires
- symfony/config: ^2.7.6|^3.0.2
- symfony/console: ^2.7.6|^3.0.2
- symfony/dependency-injection: ^2.7.6|^3.0.2
- symfony/http-kernel: ^2.7.6|^3.0.2
- symfony/process: ^2.7.6|^3.0.2
Requires (Dev)
- phpunit/phpunit: ~5.2
- symfony/framework-bundle: ^2.7.6|^3.0.2
This package is not auto-updated.
Last update: 2020-08-14 02:43:51 UTC
README
HshnNpmBundle 添加了使用 npm 管理节点模块的支持。
包含的功能
- 使用一条命令在您的包中安装节点模块
- 使用一条命令在您的包中调用 npm 脚本
- 单元测试
安装
1. 使用 composer 下载 HshnNpmBundle
$ php composer.phar require hshn/npm-bundle
2. 启用包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Hshn\NpmBundle\HshnNpmBundle(), ); }
3. 配置 HshnNpmBundle
在 config.yml
文件中为您的包启用节点模块管理。
# app/config/config.yml hshn_npm: bundles: YourBundle: ~
3.1. 选择包管理器(可选)
您可以指定全局使用的包管理器。
# app/config.config.yml hshn_npm: package_manager: npm # or yarn
您还可以为每个包覆盖包管理器配置。
# app/config.config.yml hshn_npm: package_manager: npm # use npm globally bundles: # FooBundle will use npm FooBundle: ~ # BarBundle will use yarn BarBundle: package_manager: yarn
4. 安装节点模块
将您的 package.json
文件放在 npm 目录中,npm 目录的默认值是 $yourBundle/Resources/npm
。
示例
{ "name": "your-bundle-name", "dependencies": { "lodash": "^4.3.0" } }
现在运行命令 app/console hshn:npm:install
来安装 npm 目录 ``$yourBundle/Resources/npm/npde_modules`` 中的所有依赖项。
5. 在构建脚本中使用已安装的节点模块
编写您喜欢的构建脚本。
gulp 示例在此 处
6. 将构建脚本注册为 npm 脚本
{ "name": "your-bundle-name", "dependencies": { "lodash": "^4.3.0" }, "scripts": { "build": "gulp build" } }
然后您可以使用以下命令运行 npm 脚本:
$ php app/console hshn:npm:run build # `npm run build` in every bundles