Got to work with local node_modules installation.
- At your app folder:
npm install --save babel-cli babel-preset-es2015 babel-preset-react babel-preset-stage-0
- manual run to test babel installation:
node_modules/.bin/babel --presets=es2015,stage-0,react
input:
let a = 5; console.log(a);
after new empty line press Ctrl+D
(EOF)
Expected output:
"use strict";
var a = 5;
console.log(a);
- create
babel_compressor.py
from this gist: https://gist.github.com/d9k/651a7f926e85cbbfbf32631983529ea2 - usage (at your web app entry point):
# change your.path.to.babel_compressor to actual path
from your.path.to.babel_compressor import BabelCompressor
from jac.config import Config as JacDefaultConfig
# . . . . .
# right before app initialization:
# check paths with debugger!
BabelCompressor.binary = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'node_modules', '.bin', 'babel'))
BabelCompressor.cwd_for_presets_search = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
jac_default_config = JacDefaultConfig()
# get jinja2_env. In Pyramid you can get it this way:
# `jinja2_env = pyramid_jinja2.get_jinja2_environment(config)`
jinja2_env.compressor_classes = jac_default_config.get('compressor_classes')
jinja2_env.compressor_classes['text/babel'] = BabelCompressor
- at your jinja2 template code:
{% compress 'js' %}
<script type="text/babel">
let a = 5;
console.log(a);
</script>
{% endcompress %}