-
Notifications
You must be signed in to change notification settings - Fork 574
Using Traceur with Node.js
Erik Arvidsson edited this page Feb 2, 2014
·
11 revisions
Using Traceur 0.0.20 or later.
Traceur allows you to hook into Node.js' require function which allows you to require ES6 modules just as if they were Node.js modules.
To do this you can either use traceur.require or you can make traceur.require the default by using traceur.require.makeDefault. makeDefault takes a function that takes the path to the file being required. If this function returns true Traceur will transform the file.
Below is a more complete example:
// test.js
import {b} from './resources/b';
console.log(b);
// resources/b.js
export var b = 'BBB';
// bootstrap.js
var traceur = require('traceur');
traceur.require.makeDefault(function(filename) {
// Change this to something more meaningful.
return filename.endsWith('test.js') || filename.endsWith('b.js');
});
require('./test');$ node bootstrap.js
BBB