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

create a build command to export packages as globals #85

Closed
millermedeiros opened this issue Apr 12, 2013 · 13 comments
Closed

create a build command to export packages as globals #85

millermedeiros opened this issue Apr 12, 2013 · 13 comments

Comments

@millermedeiros
Copy link
Member

sometimes it can be good for quick prototyping / testing on the console and some users might not be using AMD or browserify...

I'm thinking in some very quick-and-dirty solution that basically reuses the requirejs optimizer and maybe bundles the code with some very basic AMD shim

  export [packageName] [globalNamespace]
  export the given package or whole lib into the namespace (default to mout.{packageName}) 

/cc @edankwan

@ericelliott
Copy link

Browserify 2 can export globals with the -s (--standalone) option.

@millermedeiros
Copy link
Member Author

see also global-wrap

@millermedeiros
Copy link
Member Author

amdclean almost works, they just need to fix a couple bugs (gfranko/amdclean#8, gfranko/amdclean#10) or we need to change our code a little bit.

@millermedeiros
Copy link
Member Author

just tried global-wrap and it works!

require('global-wrap')({
  main: 'node_modules/mout/index.js',
  global:'mout'
}, function(err, out){
  require('fs').writeFileSync('mout.js', out);
});

in the end, the format they use is very similar to AMD, don't even know why they did not decide to use the AMD simplified CJS as the transport format; but at least it exposes a single global and is automatic.

maybe we should use any of these approaches on a future release, not that I care too much about users that are using globals (everyone should be using modules nowadays!!!)

@jmdobry
Copy link

jmdobry commented May 17, 2014

grunt-mout can be used to generate custom browserify builds exported to the mout global.

@edankwan
Copy link

Is it possible to inject an object getter for each modules for the dev version to log which modules have been used and then the user can generate the custom build with that result without manually look for which modules had been used?

@jmdobry
Copy link

jmdobry commented May 17, 2014

Like a dry run with informative logging output? Or would the file be
generated with a comment block at the top listing the included modules?
On May 17, 2014 3:08 AM, "Edan Kwan" notifications@github.com wrote:

Is it possible to inject an object getter for each modules for the dev
version to log which modules have been used and then the user can generate
the custom build with that result without manually look for which modules
had been used?


Reply to this email directly or view it on GitHubhttps://github.com//issues/85#issuecomment-43401919
.

@jmdobry
Copy link

jmdobry commented May 17, 2014

Or you mean actual code that logs which pieces they use because they
themselves don't know?
On May 17, 2014 3:08 AM, "Edan Kwan" notifications@github.com wrote:

Is it possible to inject an object getter for each modules for the dev
version to log which modules have been used and then the user can generate
the custom build with that result without manually look for which modules
had been used?


Reply to this email directly or view it on GitHubhttps://github.com//issues/85#issuecomment-43401919
.

@jmdobry
Copy link

jmdobry commented May 17, 2014

@edankwan I added support for spying on your app's usage of mout.

First generate a spyable mout bundle that contains all of the modules:

grunt.initConfig({
  mout: {
    dist: {
      options: {
        spy: true
      },
      dest: './.tmp/mout.js'
    }
  }
});

Then load the generated mout bundle into your app and perform a lot of actions in your app to try and make sure you hit all your uses of mout.

Open up your console and run mout.usage(). This will print the list of modules that were called.

You can copy paste that list into the grunt config to create your slimmer mout build.

If mout.usage() printed ["mout/array/contains","mout/object/get"] you would change your grunt config to:

grunt.initConfig({
  mout: {
    dist: {
      options: {
        modules: [
          'mout/array/contains',
          'mout/object/get'
        ]
      },
      dest: './.tmp/mout.js'
    }
  }
});

@rafaelrinaldi
Copy link

I've been wanting this for awhile. Mostly for prototype stuff. 👍 guys.

@millermedeiros
Copy link
Member Author

@jmdobry awesome stuff!!

@edankwan
Copy link

This is exactly what I want!!! Good job!! Thanks!!!

@millermedeiros
Copy link
Member Author

going to close this since there are many options available and most people that uses mout should really be loading the individual modules anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants