Powershell build - compiling SASS

折月煮酒 提交于 2020-07-08 04:06:08

问题


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

  1. Run PowerShell as Administrator
  2. Chech policy with Get-ExecutionPolicy U will see Restricted
  3. See all policies Get-ExecutionPolicy -List
  4. Run Set-ExecutionPolicy -ExecutionPolicy Unrestricted
  5. Press "Y"

Use node-sass -w ./input.scss ./output.css

Also, U can read more here




回答4:


  1. Install Node.JS (https://nodejs.org/download/)
  2. Install Ruby for Windows (http://rubyinstaller.org/)
  3. run npm init in your project directory to create a packages.json file.
  4. install grunt npm install grunt --save-dev (http://gruntjs.com/getting-started)
  5. install grunt-contrib-sass npm install grunt-contrib-sass --save-dev
  6. create an empty Gruntfile.js in your project root
  7. add the following to your gruntfile.js

    module.exports = function(grunt) {
       // Do grunt-related things in here
    };
    
  8. 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.

  9. run grunt from a powershell window in you project root.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!