5

I have installed a widget using npm. It is installed under node_modules folder. I need to include the widget's javascript and CSS files in my View but since they are not in Web folder I can't include them, using the following method :

<link href="{{ asset('assets/someFolder/.css') }}" rel="stylesheet" type="text/css" />

How can I achieve the above?

user6368518
  • 101
  • 2
  • 13
  • The documentation suggests you use other tools like grunt and bower to build and deploy your web assets [web-assets frontend-based-applications](http://symfony.com/doc/current/best_practices/web-assets.html#frontend-based-applications) – ohvitorino Jul 18 '16 at 09:45

2 Answers2

1

There are couple of ways around this issue that I know of. I'm going to show you the way I use node_modules in symfony. I use Yarn and Assetic bundle for this, it's actually easier than you think.

  1. Install yarn for your system and install assetic bundle in symfony. They are pretty straightforward.

  2. Create a new directory inside your AppBundle (or in any of your bundles) and name it Assets. Go to your assets directory from console and install your node modules there using Yarn.

    yarn add bootstrap@3.3.7

  3. Now you can include your asset as follows in your view.

    {% stylesheets '@AppBundle/Assets/node_modules/bootstrap/dist/css/bootstrap.css' filter='cssrewrite' %} <link rel="stylesheet" href="{{ asset_url }}" /> {% endstylesheets %}

Hope this helps.

chamal101
  • 101
  • 1
  • 4
0

as explained here Specify path to node_modules in package.json there is no proper way to instruct package.json to put the dependencies in some specific path. I had to manually change to the Web folder and then download the widget's dependencies there.

Community
  • 1
  • 1
user6368518
  • 101
  • 2
  • 13