mercredi 13 juillet 2016

Transpiling es6 into es5

Ran into a problem today at work, wondering if anyone could offer some guidance. Im trying to accomplish roughly the following described below.

Files im working with:

  1. config.js : config file using es6 syntax (particularly using import keyword).
  2. script.js : node script written using node version that does not support the use of es6 syntax (particulary using import keyword). script.js aims to read the contents of config.js

    //config.js
    import _ from 'npm:lodash'
    import foo from '../otherRandomFile.js'
    var configObject = {
      randomConfigOne: true,
      randomConfigTwo: false
    }
    export default configObject;
    
    //script.js
    var config = require('../app/config.js)
    //cannot console log as below because script barfs
    //due to import being a reserved wrk
    console.log(config.randomConfigOne);
    
    

Question: What do I have to do in script.js so that I will gain access to the object exported by the config.js file without the script barfing about the fact that im trying to use es6 sytax in the file im accessing.




Aucun commentaire:

Enregistrer un commentaire