Loading ...
Sorry, an error occurred while loading the content.

server js / browser js compatible module pattern?

Expand Messages
  • AJ ONeal
    I m trying to find a method that will work for both ssjs and bsjs modules and pass JSLint I ve got a pretty decent require shim for the browser. I use a
    Message 1 of 1 , Feb 19, 2011
    • 0 Attachment
      I'm trying to find a method that will work for both ssjs and bsjs modules
      and pass JSLint

      I've got a pretty decent "require" shim for the browser.
      I use a "provide" shim for the server.


      I can't find a way to provide the globals and use strict mode and pass
      JSLint.


      This is the best I've been able to come up with so far, but it complains
      about missing "use strict" as the first line (and the dangling _, of
      course).


      // require-kiss, which provides "provide", "require", "module", and
      "exports"
      // is concatenated before this file
      // https://github.com/coolaj86/require-kiss-js
      var require, module, exports,
      __dirname = __dirname || '',
      provide = provide || function () {};
      (function () {
      "use strict";

      function SubmoduleB() {}

      // require with the full path (Node.js) or an empty one (Browser)
      var SubmoduleA = require((__dirname ? __dirname + '/' : 'mymodule') +
      '/submodule-a');

      // in the browser this is declared as a global by require-kiss
      module.exports = SubmoduleB;

      provide('mymodule/submodule-b', module.exports);
      }());



      Could there be some easy user-configurable way to define globals explicitly
      used for shimming like this?
      Or is there a way presently to get around this sort of issue?

      AJ ONeal


      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.