帮酷LOGO

Automatically pull in npm dependencies as staticfiles in your Django project

在 Django 项目中自动将npm依赖项作为 staticfiles

将光标移到/点击文章中的句子上,可以查看译文。 显示原文      显示译文      双语对照

  • 显示内容
文章标签:AUTO  NPM  PULL  依赖  STAT  proj  静态  DEP  
Automatically pull in npm dependencies as staticfiles in your Django project



  • Source Code:django-npm
  • WebSite:http://www.github.com/kevin1024/django-npm
  • django-npm Documents
  • django-npm Download
  • django-npm Build Status

    Want to use npm modules in your django project without vendoring them?django-npm serves as a wrapper around the npm command-line program as well as a staticfiles finder.

    Installation

    • $ pip install django-npm
    • Install npm. if you use a private registry, make sure your .npmrc is set up to connect to it
    • Have a package.json at the root of your project, listing your dependencies
    • Add npm.finders.NpmFinder to STATICFILES_FINDERS
    • Configure your settings.py
    • $ npm install with the command line, or with Python :from npm.finders import npm_install; npm_install()
    • $./manage.py collectstatic will copy all selected node_modules files into your STATIC_ROOT.

    Configuration

    • NPM_ROOT_PATH : absolute path to the npm" root"directory - this is where npm will look for your package.json, put your node_modules folder and look for a .npmrc file

    • NPM_EXECUTABLE_PATH : (optional) defaults to wherever npm is on your PATH.if you specify this, you can override the path to the npm executable.this is also an absolute path.

    • NPM_STATIC_FILES_PREFIX : (optional) your npm files will end up under this path inside static.i usually use something like os.path.join('js', 'lib') (so your files will be in/static/js/lib/react.js for example) but you can leave it blank and they will just end up in the root.

    • NPM_FILE_PATTERNS : (optional) by default, django-npm will expose all files in node_modules to Django as staticfiles.you may not want all of them to be exposed.you can pick specific files by adding some additional configuration :

      NPM_FILE_PATTERNS= {
       'react': ['react.js'],
       'express': ['lib/*.js', 'index.js']
      }

      Keys are the names of the npm modules, and values are lists containing strings.the strings match against glob patterns.

    • NPM_FINDER_USE_CACHE : (default True) A boolean that enables cache in the finder.if enabled, the file list will be computed only once, when the server is started.

    npm install

    If you want to run npm install programmatically, you can do :

    from npm.finders import npm_install
    npm_install()

    Changelog

    • v1.0.0 - Improve speed, separate npm install from the finder
    • v0.1.4 - Fix bug with NPM_EXECUTABLE_PATH (thanks @yohanboniface)
    • v0.1.3 - actually fix destination bug
    • v0.1.2 - Fix bug with destination prefix
    • v0.1.1 - manage.py runserver bugfix
    • v0.1.0 - Add NPM_FILE_PATTERNS setting
    • v0.0.1 - initial release


    文章标签:STA  AUTO  proj  STAT  DEP  静态  PULL  依赖  

    Copyright © 2011 HelpLib All rights reserved.    知识分享协议 京ICP备05059198号-3  |  如果智培  |  酷兔英语