You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
George Yong edited this page Oct 14, 2016
·
11 revisions
Using Traceur 0.0.20 or later.
Traceur allows you to hook into Node.js' require function to allow you to require() ES6 modules just as if they were Node.js modules. (Note that the reverse process of using existing nodejs modules in ES6 is not yet supported in Traceur, see systemjs instead).
To do this you can either use traceur.require or you can make traceur.require the default by using traceur.require.makeDefault([filter, options]). Options are enumerated in Options.js. makeDefault optionally takes a filter function that takes the path to the file being required as input. If this function returns true Traceur will transform the file. Note: If you call makeDefault multiple times then traceur transpiles the file if at least one of the filter functions returned true.
Below is a more complete example:
// test.jsimport{configFile}from'./resources/b';// use import for ES6 modulesvar{readFileSync}=require('fs');// use require for non-ES6 Node modulesconsole.log(readFileSync(configFile,'utf-8'));