Skip to content
This repository has been archived by the owner on Jun 30, 2020. It is now read-only.
/ HshnNpmBundle Public archive

Symfony2 Bundle to manage node modules for each bundles in your app

License

Notifications You must be signed in to change notification settings

hshn/HshnNpmBundle

Repository files navigation

HshnNpmBundle

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

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.

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

3.1. Choose package manager (optional)

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

4. Installing node modules

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

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

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

About

Symfony2 Bundle to manage node modules for each bundles in your app

Resources

License

Stars

Watchers

Forks

Packages

No packages published