Skip to content

Instantly share code, notes, and snippets.

@numtel
Created April 29, 2015 00:15
Meteor dirmap

From what I can tell, accomplishing a more automatic lazy-loading system would require the current file bundling scheme to be amended to support applications written with explicit source file dependency trees.

With the dependency tree, an intelligent lazy-loader could decide which files are necessary for which routes/templates.

In order to not break compatibility with existing applications, the directories used must become configurable.

The default configuration could be described in a file such as .meteor/dirmap.json:

{
  // client and server accept array of filenames/pattern matchers
  client: [
    'client/*'
  ],
  server: [
    'server/*'
  ],
  // Asset roots expect a directory path string
  clientAssetRoot: 'public/',
  serverAssetRoot: 'private/',
  // What to do with source files not described above
  includeBalance: ['client', 'server']
}

Source files bundled by the dirmap become the root nodes of the dependency tree with their children determined by the Meteor.addFiles() calls contained.

An ignore option which accepts an array would also be helpful in many situations.

Including files from within any source file (instead of just a package.js file) would allow dependency trees to be built. Specifically not using ES6 includes so that any file type can be used.

if(Meteor.isClient) {
  // Can only import files to the client, no second argument necessary
  Meteor.addFiles([
    'sometemplates.html',
    'somescripts.es6',
    'styles.less'
  ])
}
else if(Meteor.isServer) {
  // Add files to clients
  Meteor.addFiles('my_module/*', 'client')
  // Or include files 
  Meteor.addFiles('server_stuffs/*', 'server')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment