Multiple files in data/, What do require and package.json look like?

If I make a new file in data/ (in addition to my existing data.js) named lbLogin.js that exports lbLogin, how do I modify package.json?
And how do I require it's modules?
Currently my data/package.json is:
{
  "main": "data.js"
}
And when I need the modules exported by data.js I can: data = require('../data'), and access it's mftUserLoginModel module with data.mftUserLoginModel. What would the corresponding require look like for lbLogin?
If there is any existing example of an Enyo project with multiple data or view files I haven't been able to find it yet...

Comments

  • Sounds like data isn't itself a module but just a directory of modules. In that case, you could omit the package.json and import each module directly.
    require('../data/data') // little redundant looking ...
    require('../data/lbLogin')
    
  • Thanks for the reply @theryanjduffy ,
    I could use a little more help in understanding how to "fix" package.json. If I were to refactor the modules currently in data.js out into separate files, how should those files be keyed in package.json?
    In the template generated package.json files when there is only one file it is keyed as "main" although I don't see that key being used anywhere...
    Should I key lbLogin as "lbLogin"?
    {
      "main": "data.js",
      "lbLogin": "lbLogin.js"
    }
    ?
  • edited September 2016
    package.json can only refer to a single entry point via the main key. If you refactor your data.js into separate files all within the data directory, you could omit the package.json and refer to each individually:
    require('../data/file1');
    require('../data/file2');
    Assuming a file system like:

    + src
    + data
    + file1.js
    + file2.js
    + components
    + component.js
Sign In or Register to comment.