跳转到主要内容

使用runserver和collectstatic运行gulp任务

项目描述

django-gulp 重写了 ./manage.py runserver./manage.py collectstatic,以便它们也能运行您的gulp任务。

我已将其与gulp中的watchify和livereload结合使用,这样我的简单的未装饰的runserver可以自动监视和编译新的JavaScript文件,并自动从SASS编译并实时刷新新的CSS。

安装

"django_gulp" 添加到您的 INSTALLED_APPS 设置中,如下所示,确保它在 django.contrib.staticfiles(或列表中重写 runservercollectstatic 的其他应用程序)之前。

INSTALLED_APPS = (
    'django_gulp',
    ...
)

现在,当您运行 ./manage.py runserver./manage.py collectstatic 时,您的gulp任务也会运行!

设置

GULP_CWD 默认为当前工作目录。如果你的 gulpfile.js 文件不在 Django 项目的顶级目录中,请覆盖它。

GULP_PRODUCTION_COMMAND 默认为 gulp build --productionGULP_DEVELOP_COMMAND 默认为 gulp。注意,当手动指定此设置时,GULP_CWD 会被忽略。

Heroku

django-gulp 在 Heroku 上运行!你只需要使用 buildpack-multi 并确保你的 .buildpacks 文件如下所示

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

要使用 buildback-multi,请按以下方式设置配置

$ heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-multi.git

示例输出

$ ./manage.py runserver
>>> Starting gulp
>>> gulp process on pid 47863
Performing system checks...

System check identified no issues.
May 04, 2015 - 18:27:52
Django version 1.8.1, using settings 'example.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[18:27:53] Using gulpfile ~/p/example/gulpfile.js
[18:27:53] Starting 'bower-install'...
[18:27:54] Using cwd:  /Users/beau/p/example
[18:27:54] Using bower dir:  static/vendor
[18:27:54] Starting 'sass'...
[18:27:54] Starting 'watch'...
[18:27:54] Finished 'watch' after 19 ms
[18:27:54] Starting 'watchify'...
[18:28:08] Watching files required by bundle-about.js
[18:28:08] Bundling bundle-about.js...
[18:28:08] Watching files required by bundle-accounts-login.js
[18:28:08] Bundling bundle-accounts-login.js...
[18:28:08] Watching files required by bundle-accounts-signup.js
[18:28:08] Bundling bundle-accounts-signup.js...
[18:28:08] Watching files required by bundle-activities.js
[18:28:08] Bundling bundle-activities.js...
[18:28:08] Finished 'watchify' after 14 s
[18:28:09] Finished 'sass' after 15 s
^C>>> Closing gulp process
$ ./manage.py collectstatic
[18:32:54] Using gulpfile ~/p/example/gulpfile.js
[18:32:54] Starting 'bower-install'...
[18:32:55] Using cwd:  /Users/beau/p/example
[18:32:55] Using bower dir:  static/vendor
[18:32:55] Starting 'sass'...
[18:32:56] Starting 'browserify'...
[18:33:05] Bundling bundle-about.js...
[18:33:05] Bundling bundle-accounts-login.js...
[18:33:05] Bundling bundle-accounts-signup.js...
[18:33:05] Bundling bundle-activities.js...
[18:33:05] Finished 'browserify' after 9.39 s
[18:33:08] Finished 'sass' after 13 s
[18:33:14] Finished 'bower-install' after 19 s
[18:33:14] Starting 'bower-main-files'...
[18:33:14] Starting 'bower-detritus'...
[18:33:14] Finished 'bower-main-files' after 104 ms
[18:33:14] Finished 'bower-detritus' after 507 ms
[18:33:14] Starting 'bower'...
[18:33:14] Finished 'bower' after 18 μs
[18:33:14] Starting 'build'...
[18:33:14] Finished 'build' after 5 μs

You have requested to collect static files at the destination
location as specified in your settings:

    /Users/beau/p/example/static-files

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Copying '/Users/beau/p/example/build/js/bundle-about.js'
Copying '/Users/beau/p/example/build/js/bundle-about.map.json'
Copying '/Users/beau/p/example/build/js/bundle-accounts-login.js'
Copying '/Users/beau/p/example/build/js/bundle-accounts-login.map.json'
Copying '/Users/beau/p/example/build/js/bundle-accounts-signup.js'
Copying '/Users/beau/p/example/build/js/bundle-accounts-signup.map.json'
Copying '/Users/beau/p/example/build/js/bundle-activities.js'
Copying '/Users/beau/p/example/build/js/bundle-activities.map.json'

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

django-gulp-4.1.0.tar.gz (6.4 kB 查看散列)

上传时间

构建分布

django_gulp-4.1.0-py2.py3-none-any.whl (7.0 kB 查看散列)

上传时间 Python 2 Python 3

由以下机构支持