Skip to content

Commit 57593e7

Browse files
committed
Add ES6 support via 6to5.
1 parent 4751a12 commit 57593e7

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

docs/compilers.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,34 @@ To use it add this to your ``PIPELINE_COMPILERS`` ::
144144
Defaults to ``''``.
145145

146146

147+
ES6 compiler
148+
============
149+
150+
The ES6 compiler uses `6to5 <https://6to5.org>`_
151+
to convert ES6+ code into vanilla ES5.
152+
153+
To use it add this to your ``PIPELINE_COMPILERS`` ::
154+
155+
PIPELINE_COMPILERS = (
156+
'pipeline.compilers.es6.ES6Compiler',
157+
)
158+
159+
160+
``PIPELINE_6TO5_BINARY``
161+
--------------------------
162+
163+
Command line to execute for 6to5 program.
164+
You will most likely change this to the location of 6to5 on your system.
165+
166+
Defaults to ``'/usr/bin/env 6to5'``.
167+
168+
``PIPELINE_6TO5_ARGUMENTS``
169+
-----------------------------
170+
171+
Additional arguments to use when 6to5 is called.
172+
173+
Defaults to ``''``.
174+
147175

148176
Write your own compiler class
149177
=============================

pipeline/compilers/es6.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from __future__ import unicode_literals
2+
3+
from pipeline.conf import settings
4+
from pipeline.compilers import SubProcessCompiler
5+
6+
7+
class ES6Compiler(SubProcessCompiler):
8+
output_extension = 'js'
9+
10+
def match_file(self, path):
11+
return path.endswith('.es6')
12+
13+
def compile_file(self, infile, outfile, outdated=False, force=False):
14+
if not outdated and not force:
15+
return # File doesn't need to be recompiled
16+
command = "%s %s %s -o %s" % (
17+
settings.PIPELINE_6TO5_BINARY,
18+
settings.PIPELINE_6TO5_ARGUMENTS,
19+
infile,
20+
outfile
21+
)
22+
return self.execute_command(command)

pipeline/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
'PIPELINE_COFFEE_SCRIPT_BINARY': '/usr/bin/env coffee',
4949
'PIPELINE_COFFEE_SCRIPT_ARGUMENTS': '',
5050

51+
'PIPELINE_6TO5_BINARY': '/usr/bin/env 6to5',
52+
'PIPELINE_6TO5_ARGUMENTS': '',
53+
5154
'PIPELINE_LIVE_SCRIPT_BINARY': '/usr/bin/env lsc',
5255
'PIPELINE_LIVE_SCRIPT_ARGUMENTS': '',
5356

0 commit comments

Comments
 (0)