/python-requirejs

Run RequireJS (r.js) from Python without needing node or rhino.

Primary LanguageJavaScriptMIT LicenseMIT

python-requirejs

Run RequireJS (r.js) from Python without requiring Node or Rhino. Leverages PyMiniRacer plus a minimal JS environment to make r.js think it's running in node.

Latest PyPI Release Release Notes License GitHub Stars GitHub Forks GitHub Issues

Travis Build Status Python Support

Usage

python-requirejs is available via PyPI:

pip install requirejs

API

import requirejs

requirejs.optimize(
    appDir=".",
    baseUrl="js/",
    modules=[{
        "name": "main",
    }]
    dir="../build",
)

Hopefully, all of the available build options for r.js will Just Work. If you find any discrepancies, please open a ticket to let us know.

This library is meant to be a drop-in replacement for node r.js -o app.build.json, and is tested by comparing its output with that command. However, since the optimize API is being called as a function, you may need to set the working directory explicitly to avoid any unexpected differences in how relative paths are computed:

import requirejs
import json

with open('app/app.build.json') as f:
    config = json.load(f)

requirejs.optimize(
    config,
    working_directory="app/"  # Unique to python-requirejs
)