GithubHelp home page GithubHelp logo

Problem using SystemJS/JSPM? about gulp-umd HOT 2 OPEN

nicklasb avatar nicklasb commented on August 10, 2024 2
Problem using SystemJS/JSPM?

from gulp-umd.

Comments (2)

nicklasb avatar nicklasb commented on August 10, 2024

@eduardolundgren This seems to annoy RequireJS as well. Sort of defies the UMD thoughts.

from gulp-umd.

CodeMan99 avatar CodeMan99 commented on August 10, 2024

@nicklasb Hopefully you have identified a pattern that works for you.

The pattern you have in the original issue is that somewhere in "......my code......" you should define an export variable. Usually this is an object or constructor.

Say you have a class you named "Engine". You write a file like this named "engine.js".

function Engine(valves) {
   this.valves = valves;
}

Engine.prototype.start = function() {
   // make the starter motor turn and send fuel into the injection system.
};

In your dev environment Engine is a global. But when you ship you want to make it private if possible.

;(function(root, factory) {
   if (typeof define === 'function' && define.amd) {
      define(['starter', 'fuel-injection'], factory);
   } else if (typeof exports === 'object') {
      module.exports = factory(require('starter'), require('fuel-injection'));
   } else {
      root.Engine = factory(root.starter, root.fuelInjection);
   }
}(this, function(starter, fuelInjection) {
   function Engine(valves) {
      this.valves = valves;
   }

   Engine.prototype.start = function() {
      // make the starter motor turn and send fuel into the injection system.
   };

   return Engine;
}));

You can also change what value is returned by the "factory" function by providing the name via exports configuration option.

Say instead of Engine you called your class CombustionEngine.

var options = {
   exports: function(file) {
      if (file.basename === 'engine.js') {
         return 'CombustionEngine';
      }
      // file is a vinyl instance: https://github.com/gulpjs/vinyl#filestem
      return file.stem;
   }
};
gulp.src('*.js')
   .pipe(umd(options))
   .pipe(gulp.dest('dist'));

By the way, I am a new maintainer here, so at some point I will go about improving the documentation.

from gulp-umd.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.