Minified version of wire

41 views
Skip to first unread message

Remy

unread,
Aug 18, 2014, 6:54:20 PM8/18/14
to cuj...@googlegroups.com
Hello,

I'm using wire in a project loaded with requirejs, but I in the future we will probably want to use a minified version of wire as a lot of requests are made. The biggest number of requests are made for wire so I would love to just have wire and all of its dependencies contained in a single file.

I tried to minify just wire together with when and meld with r.js using this configuration file that I hacked up with my very limited experience with r.js:

({
    baseUrl
: ".",
    name
: "wire/wire",
   
out: "wire.min.js",
    paths
: {
       
"when": "when/when",
       
"when/sequence": "when/sequence",
       
"meld": "meld/meld",
       
"when/timeout": "when/timeout",
       
"lib/decorators": "when/lib/decorators",
       
"lib/timer": "when/lib/timer",
       
"lib/TimeoutError": "when/lib/TimeoutError",
       
"lib/makePromise": "when/lib/makePromise",
       
"lib/Promise": "when/lib/Promise",
       
"lib/Scheduler": "when/lib/Scheduler",
       
"lib/async": "when/lib/async",
       
"lib/Queue": "when/lib/Queue",
       
"when.js": "when/when"
   
},
    optimize
: "none"
})


This is where I get stuck

r.js -o wire.build.js                                                                                                                                                      

Tracing dependencies for: wire/wire
Error: ENOENT, no such file or directory '/javascript/vendor/when/when/when.js'
In module tree:
    wire
/wire
      wire
/lib/context
        wire
/lib/Container
          wire
/lib/scope
           
when/sequence

Error: Error: ENOENT, no such file or directory '/javascript/vendor/when/when/when.js'
In module tree:
    wire
/wire
      wire
/lib/context
        wire
/lib/Container
          wire
/lib/scope
           
when/sequence

    at
Object.fs.openSync (fs.js:427:18)

I have googled but I could not find a minified version of wire and I have trouble minifying it myself. Do you have advice or tips for me?

Thank you for reading, Remy


Adam Jorgensen

unread,
Aug 19, 2014, 5:21:35 AM8/19/14
to cuj...@googlegroups.com
I think perhaps you are declaring when wrong. It needs to be defined as a package.


Your loader config should look like this:


// using requirejs
requirejs.config({
  packages: [
    { name: 'when', location: '/path/to/when', main: 'when' }
  ]
});

// using curl.js
curl.config({
  packages: {
    when: { location: '/path/to/when', main: 'when' }
  }
});


--
You received this message because you are subscribed to the Google Groups "cujojs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cujojs+un...@googlegroups.com.
To post to this group, send email to cuj...@googlegroups.com.
Visit this group at http://groups.google.com/group/cujojs.
To view this discussion on the web visit https://groups.google.com/d/msgid/cujojs/e8604a10-292d-4a92-aaea-6faf961cb98f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

unscriptable

unread,
Aug 19, 2014, 10:32:39 AM8/19/14
to cuj...@googlegroups.com
Hey Remy,

Adam is right.  The norm with modular code is to use `packages`.  `paths` is typically used for legacy code that was migrated to AMD (like jQuery).  All of the cujojs libraries should be configured as packages.  

Also, don't refer to your main modules as "when/when" and "wire/wire".  Notice how Adam specified a `main` for each package.  This allows code to just say "when" or "wire" or "meld" and get the *main* module within each package.

Here's a guess at what your r.js config should look like (I don't know r.js very well):

({
    baseUrl
: ".",
    name
: "wire",
   
out: "wire.min.js",
    packages
: [
       
{ name: "when", location: "when", main: "when" },
       
{ name: "meld", location: "meld", main: "meld" },
       
{ name: "wire", location: "wire", main: "wire" }
   
],
    modules
: [
       
// put any *additional* when or wire modules here, for instance:
       
"wire/dom",
       
"wire/dom/render"
   
],
    optimize
: "none"
})

The list of `modules` should only be module that aren't automatically loaded when you `require('when')` or `require('wire')`.

Does that help?

Regards,

-- John

Remy

unread,
Aug 19, 2014, 3:29:18 PM8/19/14
to cuj...@googlegroups.com
Thank you Adam and John! That was the exact config I needed to minify wire.
I did not expect the r.js config file to resemble a normal main.js file like that.

Thanks for taking the time to help me!

Reply all
Reply to author
Forward
0 new messages