Handle asset dependencies and scripts with npm

v0.2.0 2016-04-20 13:00 UTC


Build Status Latest Stable Version Latest Unstable Version

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


1. Download HshnNpmBundle using composer

$ php composer.phar require hshn/npm-bundle

2. Enable the bundles


// app/AppKernel.php
public function registerBundles()
    $bundles = array(
        // ...
        new Hshn\NpmBundle\HshnNpmBundle(),

3. Configure the HshnNpmBundle

Enable node modules management for your bundles in the config.yml file.

# app/config/config.yml
        YourBundle: ~

4. Installing node modules

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`.

5. Use the installed node modules in your build scripts

Write build scripts you like.

gulp example is here

6. Register your build scripts as a npm script

    "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