using less with symfony2 on windows

2019-06-06 16:13发布

Im trying to get Less with assetic working while developing on a windows OS.

Im loading an existing project of which I can alter the config.yml and parameters.yml files as necessary.

steps so far:

  1. I have installed Node.js via the msi installer
  2. I have used npm and installed less gloabally

config.yml

assetic:
      debug:          %kernel.debug%
      use_controller: false
      bundles:        [ FOSUserBundle ]
      filters:
          less:
              node: "C:\\Program Files (x86)\\nodejs\\node.exe" #/usr/local/bin/node
              node_paths: [C:\Users\matt\AppData\Roaming\npm\node_modules\less] #[ /usr/local/lib/node_modules ]
              apply_to: "\.less$"

Ive tried moving the appdata/roaming/npm/node_modules/less dir straight into the local node_modules dir in program files (x86)/nodejs/node_modules dir to no avail.

Ive also tried setting adding the roaming/npm/node_modules/less dir to the environment path, no joy.

Ive tried installing less directly into the project and pointing the node_path directly to it, no joy.

the error in the outputted css file is as below:

[exception] 500 | Internal Server Error | Assetic\Exception\FilterException [message] An error occurred while running: "C:\Program Files (x86)\nodejs\node.exe" "C:\Users\Matt\AppData\Local\Temp\assEC1E.tmp"

(which is rather unhelpful)

any help appreciated, we're all a bit stuck in the office.

1条回答
戒情不戒烟
2楼-- · 2019-06-06 17:06

This is an old question but, as I've found the same problem and I finally solved it, I wanted to post the answer.

The recommended way to use LESS on Windows is to use lessphp package. To add it you just add in your composer json the following line:

"require": {
    .....
    "leafo/lessphp": "dev-master",
    .....
}

Then you must run

$ php composer.phar update

and update your app/config/config.yml with this configuration:

assetic:
    #...
    filters:
        lessphp:
            file: %kernel.root_dir%/../vendor/leafo/lessphp/lessc.inc.php
            apply_to: "\.less$"

Once you have do this, you will be able to preprocess the LESS files and generate the CSS files.

Then when you want to process the files with assetic you just have to include that filter in your views like, for example:

{% stylesheets filter='lessphp' output='css/main.css'
    '@AppBundle/Resources/public/less/*'
%}
查看更多
登录 后发表回答