Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Common.JS / Node.js module support to models #102

Closed
wants to merge 1 commit into from

Conversation

DanielApt
Copy link

Allow models to either be loaded via a script tag:

<script src="models/model_pca_10_mosse.js"></script>

or via CommonJS / Node.js modules

// Without ES6 support
var pModule = require('models/model_pca_10_mosse');

// With ES6 support
import pModule from 'models/model_pca_10_mosse';

As Github's UI does not allow viewing such large files, the summary of the change looks as follows:

Before

var pModel = {...};

After

(function (global) {
  'use strict';

  var pModel = {...};

  // CommonJS and Node.js module support
  if (typeof exports !== 'undefined') {
    // Support Node.js specific `module.exports` (which can be a function)
    if (typeof module !== 'undefined' && module.exports) {
      exports = module.exports = pModel;
    }
    // But always support CommonJS module 1.1.1 spec (`exports` cannot be a function)
    exports.pModel = pModel;
  } else {
    // No CommonJS or Node.js module support, export to the global (window)
    global.pModel = pModel;
  }
})(this);

@auduno
Copy link
Owner

auduno commented Jul 5, 2017

Thanks very much for the PR! This has now been manually merged into master with this commit. Github does not manage to resolve that to this pull request, so I'll have to close this manually.

@auduno auduno closed this Jul 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants