2017 © Pedro Peláez
 

symfony-bundle npm-bundle

Handle asset dependencies and scripts with npm

image

hshn/npm-bundle

Handle asset dependencies and scripts with npm

  • Thursday, August 31, 2017
  • by hshn
  • Repository
  • 1 Watchers
  • 4 Stars
  • 19,269 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 5 % Grown

The README.md

HshnNpmBundle

Build Status Latest Stable Version Latest Unstable Version, (*1)

The HshnNpmBundle adds support for managing node modules with npm., (*2)

Features included:, (*3)

  • Install node modules in your bundles with one command
  • Invoke npm scripts in your bundles with one command
  • Unit tested

Installation

1. Download HshnNpmBundle using composer

$ php composer.phar require hshn/npm-bundle

2. Enable the bundles

<?php

// 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., (*4)

# app/config/config.yml
hshn_npm:
    bundles:
        YourBundle: ~

3.1. Choose package manager (optional)

You can specify package manager which will be used globally., (*5)

# app/config.config.yml

hshn_npm:
    package_manager: npm # or yarn

Also you can override package manager configuration per bundles., (*6)

# 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. Installing node modules

Place your package.json in the npm directory, the default value for the npm dir is $yourBundle/Resources/npm., (*7)

Example:

{
    "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`., (*8)

5. Use the installed node modules in your build scripts

Write build scripts you like., (*9)

gulp example is here, (*10)

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:, (*11)

$ php app/console hshn:npm:run build # `npm run build` in every bundles

The Versions