简体   繁体   English

Azure网站和Sass

[英]Azure Websites and Sass

I have been trying to find if there is a way to support sass with a windows azure website? 我一直试图找到一种方法来支持Windows天蓝网站sass? Can someone point me to some documentation or let me now if this is even possible. 如果有可能,有人可以指点我一些文件或现在让我。 I am specifically looking to support Zurb Foundation responsive framework which is built on sass(scss). 我特别希望支持基于sass(s​​css)构建的Zurb Foundation响应框架。

I already do this by using the complied css files with an override css file. 我已经通过使用带有覆盖css文件的编译css文件来完成此操作。 I would like to use the semantic styling of sass if possible. 如果可能的话,我想使用sass的语义样式。

Thanks 谢谢

Yes. 是。 But there are a few hoops because of Sass/SCSS. 但是由于Sass / SCSS,有一些箍。

By default, Foundation uses Compass for its SCSS compilation. 默认情况下,Foundation使用Compass进行SCSS编译。 However, Sass and Compass are both written in Ruby, which Azure WebSites does not support. 但是,Sass和Compass都是用Ruby编写的,Azure WebSites不支持。 (Azure WebSites currently supports .NET, Node.js, PHP, and Python .) Running compass from the command line compiles your SCSS into the CSS needed by your browser and referenced in your HTML; (Azure WebSites目前支持.NET,Node.js,PHP和Python 。)从命令行运行compass将SCSS编译为浏览器所需的CSS并在HTML中引用; this CSS (really, the entire Stylesheet directory) is not committed into Git. 这个CSS(实际上,整个样式表目录)没有提交到Git中。

If you want to manually deploy your application into Azure WebSites, then just run Compass before hand, and then push up your files, including the generated stylesheet/ directory. 如果要将应用程序手动部署到Azure WebSites中,则只需先运行Compass,然后再推送文件,包括生成的stylesheet/目录。 However, I'm assuming you want to run through Git Deployment. 但是,我假设你想要通过Git部署。

Because Azure WebSites does not support Ruby, that means we need to have an entirely Ruby-free option. 因为Azure WebSites不支持Ruby,这意味着我们需要一个完全没有Ruby的选项。 Fortunately, Foundation already supports this using the LibSass library. 幸运的是,Foundation已使用LibSass库支持此功能。 When you create your new Foundation project, use the --libsass flag. 创建新的Foundation项目时,请使用--libsass标志。

foundation new PROJECT_NAME --libsass

Instead of running compass watch to monitor and compile your SCSS files, this uses Node.js and GruntJS. 这不使用compass watch来监视和编译SCSS文件,而是使用Node.js和GruntJS。 Execute grunt from the command line to monitor and compile your SCSS. 从命令行执行grunt以监视和编译SCSS。 (Watch and Build are the default tasks for Foundation's Grunt setup, so you don't need to specify the task name.) (Watch and Build是Foundation的Grunt设置的默认任务,因此您无需指定任务名称。)

From there, you can use the Azure CLI and Kudu to configure your Azure Git Deployment to execute Grunt to compile your SCSS as a part of your deployment. 从那里,您可以使用Azure CLI和Kudu配置Azure Git部署以执行Grunt,以将SCSS编译为部署的一部分。

Install the Azure CLI 安装Azure CLI

npm install -g azure-cli

Then start with a Node.js Deployment (which powers Grunt). 然后从Node.js部署(为Grunt提供动力)开始。

azure site deploymentscript --node

You will need to modify your deployment script ( deploy.sh ) that the Azure CLI generates so that it will execute Grunt on deploy. 您需要修改Azure CLI生成的部署脚本( deploy.sh ),以便它在部署时执行Grunt。 In deploy.sh , there is a # Deployment section. deploy.sh ,有# Deployment部分。 Replace the entire section with the following: 用以下内容替换整个部分:

# Deployment
# ----------

echo Handling node.js grunt deployment.

# 1. Select node version
selectNodeVersion

# 2. KuduSync to wwwroot
"$KUDU_SYNC_CMD" -v 500 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.deployment;deploy.sh;README.md;"
exitWithMessageOnError "Kudu Sync to Target failed"

# 3. Install npm packages
if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
  eval $NPM_CMD install
  exitWithMessageOnError "npm failed"
fi

# 4. Install bower packages
if [ -e "$DEPLOYMENT_TARGET/bower.json" ]; then
  eval $NPM_CMD install bower
  exitWithMessageOnError "installing bower failed"
  ./node_modules/.bin/bower install
  exitWithMessageOnError "bower failed"
fi

# 5. Run grunt
if [ -e "$DEPLOYMENT_TARGET/Gruntfile.js" ]; then
  eval $NPM_CMD install grunt-cli
  exitWithMessageOnError "installing grunt failed"
  ./node_modules/.bin/grunt --no-color build
  exitWithMessageOnError "grunt failed"
fi

This will (1) install all of the npm packages you need (like node-libsass ), install all of the bower packages you need (like foundation ), and run grunt build to compile your SCSS. 这将(1)安装所需的所有npm软件包(如node-libsass ),安装所需的所有bower软件包(如foundation ),并运行grunt build来编译SCSS。

One caveat 一个警告

Azure WebSites also doesn't support compiling Node.js packages. Azure WebSites也不支持编译Node.js包。 It will run the package, but it won't compile them, so they will need to be precompiled and then committed into Git. 它将运行包,但它不会编译它们,因此需要对它们进行预编译,然后将其提交到Git中。 This means that ./node_modules/node-sass/** will need to be committed into Git. 这意味着./node_modules/node-sass/**将需要提交到Git中。 Also: since modules will compile differently on OSX vs. Windows, this means that you need to commit node-sass from a Windows machine so that a Windows-compiled version of the module is in Git. 另外:由于模块在OSX与Windows上的编译方式不同,这意味着您需要从Windows机器提交node-sass,以便该模块的Windows编译版本在Git中。

Unfortunately, this will cause problems if you try and run this project from an OSX development machine. 不幸的是,如果您尝试从OSX开发机器运行此项目,这将导致问题。

All problems that don't exist under LESS. LESS下不存在的所有问题。 Since LESS originated in the JavaScript community rather than the Ruby community, its primary interpreters are in JavaScript and natively supported by Node.js (and thus Azure WebSites). 由于LESS起源于JavaScript社区而不是Ruby社区,因此它的主要解释器采用JavaScript,并由Node.js(以及Azure WebSites)本机支持。 These JavaScript interpreters also do not need to be compiled, so they don't need their node_modules committed. 这些JavaScript解释器也不需要编译,因此它们不需要提交node_modules。 But since Foundation uses Sass, these are the hoops you have to jump through. 但是由于基金会使用Sass,这些都是你必须要跳过的箍。

Not that LESS doesn't have its own issues, just different ones, and not these. 并不是说LESS没有自己的问题,只有不同的问题,而不是这些问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM