问题
I'm hoping to start using SASS in a Visual Studio 2010 project using Web Workbench - but the issue of version control through TFS has me stumped. To avoid overriding someone else's changes I understand that the outputted CSS should be excluded from source control, and that the SCSS should be compiled to CSS server side during the build process. Currently we use a Powershell script for the build, but I can't seem to find any information on how to incorporate SCSS compilation in Powershell. Is there any decent documentation out there on this process?
回答1:
I think my lack of experience with Powershell/build scripts in general had me overthinking this. I took the following steps:
1) Installed Ruby for Windows from here: https://www.ruby-lang.org/en/documentation/installation/
2) Open Command Prompt -> entered gem install ruby
3) Opened PowerGUI Script Editor (already installed, but can be downloaded here: http://software.dell.com/products/powergui-freeware/)
4) Created a function to execute the following: sass -t compressed "path\sassInput.scss" "path\sassOutput.css"
And presto. I do want to have a way of doing this for each .scss file in the directory that is not a partial, but this is enough to get me started for now.
UPDATE:
This is what I ended up with for a Powershell script: (note $dirpath
is set to my project's root directory elsewhere)
$stylesheetPath = $dirpath + "App_Themes\"
$files = Get-ChildItem $stylesheetPath -Filter *.scss
for ($i=0; $i -lt $files.Count; $i++) {
$file = $files[$i]
$fileName = $file.BaseName
$filePath = $file.FullName
if (-not $fileName.StartsWith("_")) {
$newFilePath = "$stylesheetPath$fileName.css"
sass -t compressed $filePath $newFilePath
}
}
回答2:
You need a SASS compiler and your mileage may vary. The original compiler is written in Ruby, so, if you want to use that, you have to install Ruby, the SASS gem and invoke sass
from your Powershell script.
Another option is to use a compatible compiler like SassC or C6 which do not need the Ruby runtime.
回答3:
I had the same problem. U have this one because powershell have restricted executable policy. U can do next: 0. Install node.js, npm, node-sass
- Run PowerShell as Administrator
- Chech policy with
Get-ExecutionPolicy
U will see Restricted - See all policies
Get-ExecutionPolicy -List
- Run
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
- Press "Y"
Use node-sass -w ./input.scss ./output.css
Also, U can read more here
回答4:
- Install Node.JS (https://nodejs.org/download/)
- Install Ruby for Windows (http://rubyinstaller.org/)
- run
npm init
in your project directory to create a packages.json file. - install grunt
npm install grunt --save-dev
(http://gruntjs.com/getting-started) - install grunt-contrib-sass
npm install grunt-contrib-sass --save-dev
- create an empty
Gruntfile.js
in your project root add the following to your
gruntfile.js
module.exports = function(grunt) { // Do grunt-related things in here };
follow instructions here to create a grunt-sass task: https://github.com/gruntjs/grunt-contrib-sass Some simple examples are provided near the end of the readme.
run
grunt
from a powershell window in you project root.PROFIT!
this snippet might help when adding this to your automated build script:
push-location c:\dev\project
grunt
pop-location
来源:https://stackoverflow.com/questions/30170624/powershell-build-compiling-sass