The HshnNpmBundle adds support for managing node modules with npm.
Features included:
- Install node modules in your bundles with one command
- Invoke npm scripts in your bundles with one command
- Unit tested
$ php composer.phar require hshn/npm-bundle
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Hshn\NpmBundle\HshnNpmBundle(),
);
}
Enable node modules management for your bundles in the config.yml
file.
# app/config/config.yml
hshn_npm:
bundles:
YourBundle: ~
You can specify package manager which will be used globally.
# app/config.config.yml
hshn_npm:
package_manager: npm # or yarn
Also you can override package manager configuration per bundles.
# 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
Place your package.json
in the npm directory, the default value for the npm dir is $yourBundle/Resources/npm
.
{
"name": "your-bundle-name",
"dependencies": {
"lodash": "^4.3.0"
}
}
Now run the command app/console hshn:npm:install
to install all the dependencies in the npm directory ``$yourBundle/Resources/npm/npde_modules`.
Write build scripts you like.
gulp example is here
{
"name": "your-bundle-name",
"dependencies": {
"lodash": "^4.3.0"
},
"scripts": {
"build": "gulp build"
}
}
then you can run the npm script by using following command:
$ php app/console hshn:npm:run build # `npm run build` in every bundles