Django管道,Heroku和SASS [英] Django Pipeline, Heroku, and SASS

查看:148
本文介绍了Django管道,Heroku和SASS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试 django-pipeline 设置,以便我可以编译和连接我的资源。我也想从我的存储库中删除编译的css文件,以避免合并冲突的拉请求。

I've been trying to get django-pipeline setup so that I can compile and concat my assets. I would also like to remove the compiled css files from my repository to avoid merge conflicts in pull requests.

我一直在试图获得django管道编译文件作为部署过程的一部分,但不能想出这一点。我使用SASS编写我的CSS。我的管道设置如下:

I've been trying to get django-pipeline to compile the files as part of the deploy process but can't figure this out. I use SASS to write my CSS. My pipeline settings look like this:

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

PIPELINE_CSS = {
    'main': {
        'source_filenames': (
            'sass/blah.scss',
            'sass/main.scss',
        ),
        'output_filename': 'css/main.css',
        'extra_context': {
            'media': 'screen',
        },
    },
}

PIPELINE_COMPILERS = (
  'pipeline.compilers.sass.SASSCompiler',
)

这在本地工作得很好,在我的/ sass文件夹中生成.css文件,然后合并为main.css文件。如果我检查这些CSS文件到我的git仓库,推到Heroku,它也可以正常工作。但是,如果我忽略它们,我想这样做,我不提交编译文件,然后django-pipeline找不到要组合的文件。我不知道我如何可以得到sass编译工作在Heroku,我找不到任何东西。

This works great locally, and generates .css files in my /sass folder, which are then combined to make the main.css file. If I check those CSS files into my git repository and push to Heroku, it also works fine. However, if I ignore them, which I would like to do so that I'm not committing compiled files, then django-pipeline can't find the files to combine. I'm not sure how I can get the sass compilation working on Heroku and I can't find anything about it.

如果需要,我可以提供更多的有关我的设置的信息

I can provide more information about my setup if needed, hopefully somebody knows something about this!

推荐答案

OK,这里是我使用 Compass 编译我的SASS文件。

OK, here's how I got this working using Compass to compile my SASS files.

  • Use multiple Heroku buildpacks - Heroku Buildpack Multi
  • Put the following in your .buildpacks file

https://github.com/heroku/heroku-buildpack-ruby.git
https://github.com/heroku/heroku-buildpack-nodejs
https://github.com/heroku/heroku-buildpack-python.git


  • 使用指南针和任何其他要求创建Gemfile。这是我的:

  • Create a Gemfile with compass and any other requirements you have. Here's mine:

    source 'https://rubygems.org'
    
    ruby '1.9.3'
    
    gem 'bootstrap-sass'
    gem 'compass'
    


  • 创建config.rb文件。这是我的。你可以看到它,需要我包括在我的Gemfile中的引导 - 萨斯:

  • Create a config.rb file. Here's mine. As you can see it, requires the bootstrap-sass that I included in my Gemfile:

    # Require any additional compass plugins here.
    require 'bootstrap-sass'
    
    # Set this to the root of your project when deployed:
    http_path = "/"
    css_dir = "app_folder/static/css"
    sass_dir = "app_folder/static/sass"
    images_dir = "app_folder/static/images"
    
    output_style = :compact
    

    有关config.rb的更多详细信息

    more details on config.rb can be found here

    安装节点包(django-pipeline wants yuglify)。您需要一个package.json文件:

    Install node packages (django-pipeline wants yuglify). You'll need a package.json file:

    {
      "dependencies": {
        "yuglify": "0.1.4"
      },
      "engines": {
        "node": "0.10.x",
        "npm": "1.3.x"
      },
      "repository": {
        "type": "git",
        "url": "your repo url"
      }
    }
    


  • 几乎准备好了...

  • ruby buildpack,它会寻找一个叫做assets的rake任务:precompile。现在你需要添加一个带有以下内容的Rakefile:

  • almost ready...
  • when Heroku runs the ruby buildpack, it will look for a rake task called assets:precompile. So now you'll need to add a Rakefile with the following:

    namespace 'assets' do
      desc 'Updates the stylesheets generated by Sass/Compass'
      task :precompile do
        print %x(compass compile --time)
      end
    end
    

    这将会编译你的样式表。你需要确保你将输出(回到config.rb)设置为django-pipeline寻找CSS文件的位置(如原始问题所示)。

    this will put compile your stylesheets. You need to make sure you set the output (back in config.rb) to the place that django-pipeline is looking for CSS files (shown in the original question).

    您应该在原始问题中摆脱这部分,因为django-pipeline不为您编译您的SASS:

    You should get rid of this part in the original question as django-pipeline isn't compiling your SASS for you:

    PIPELINE_COMPILERS = (
      'pipeline.compilers.sass.SASSCompiler',
    )
    


  • 这应该是!

  • That should be it! Deploys should just work now, and it didn't really add a significant amount of time to my deploy process.

    我想知道如何使用只有两个buildpack(显然只有一个是理想的,但我不知道是否可能)。问题是试图找到二进制路径,以便管道可以做它的东西,当它没有找到默认值。我不知道如果我不能这样做的原因是因为Heroku如何安装的东西,或者因为django管道中有一个错误,但现在这对我来说是足够好的。

    I would like to figure out how to do this using only two buildpacks (obviously only one would be ideal but I don't know if it's possible). The problem is trying to find binary paths so that pipeline can do it's thing when it doesn't find the defaults. I'm not sure if the reason I can't do this is because of how Heroku is installing things, or because there is a bug in django-pipeline, but right now this is good enough for me.

    如果你尝试这个,它不适合你,让我知道,如果我错过了一些我很乐意做更新。

    If you try this and it doesn't work for you, let me know, if I missed something I'm happy to make updates.

    这篇关于Django管道,Heroku和SASS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆