问题
I have been trying to setup Symfony2 on Windows so that I can use assetic with less.
I have installed node.js for Windows (0.6.8). Then I have run npm install less --global
and found less in C:\Users\Matt\AppData\Roaming\npm\node_modules
As far as my Symfony setup, I have the master branch of Assetic
(due to a bug I read about in 1.0.2), but the standard v1.0.1 of AsseticBundle
After some work, I was able to get an example less file to render via: http://localhost/app_dev.php/css/compiled-main_part_1_boilerplate_1.css
Then I switched a .less file that @imports other .less files (in the same subdirectory). Whenever I try to go to that page on my local server (using this less configuration) it hangs and I can see a command process and a node.exe process both running.
The command is trying to run a script in node.js which exists in my temporary directory. I can run that file through node.js in a command prompt fine, but I cannot get it to load using Symfony/Assetic.
Is there anyway to use node.js, less, and assetic on Windows?
Here is my relevant config file sections:
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [FeedStreamMainBundle]
# java: /usr/bin/java
filters:
cssrewrite: ~
less:
node: %assetic_node%
node_paths: [%assetic_less_path%]
yui_js:
jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
yui_css:
jar: %kernel.root_dir%/java/yuicompressor-2.4.2.jar
# closure:
# jar: %kernel.root_dir%/java/compiler.jar
dev config override:
assetic:
use_controller: true
in parameters.ini:
assetic_node="C:\\Program Files (x86)\\nodejs\\node"
assetic_less_path="C:\\Users\\Matt\\AppData\\Roaming\\npm\\node_modules"
回答1:
yes, use lessphp (server side)
Symfony2.1. How to integrate assetic lessphp filter. Add the following
package to your composer.json:
"require": { ... "leafo/lessphp": "dev-master", ... }
Run php composer.phar update
and update your config.yml
#... assetic: #... filters: lessphp: file: %kernel.root_dir%/../vendor/leafo/lessphp/lessc.inc.php apply_to: "\.less$"
or use the less.js (client side)
<link rel="stylesheet/less" type="text/css" href="styles.less">
<script src="less.js" type="text/javascript"></script>
回答2:
I used the following and this works for me. NOTE that it is 'node.exe' and not just node.
node: "C:\\Program Files (x86)\\nodejs\\node.exe"
node_paths: ["C:\\Users\\Ben\AppData\\Roaming\\npm\\node_modules"]
apply_to: "\.less$"
回答3:
Since no one really has any answers, I can only assume there are very few Windows developers using LESS and node.js in Symfony2.
My solution was to use lessphp which worked fine once I got it into the autoloader.
来源:https://stackoverflow.com/questions/9029821/less-windows-node-js-hanging