Absolute script uri's #119

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
1 participant

This is my first time working with Jam, and I am fairly new with require, so sorry if this is a totally noob problem/non-problem.

I was hoping to roll Jam it into an Express.js app I am working on. Maybe there is something for this that I am totally missing, but I saw #84 and think this would solve both problems. My package.json looked like this:

"jam": {
    "packageDir": "public/js/lib",
    "baseUrl": "public/js",
    "dependencies": {
        "jquery": "1.8.3"
    }
}

After building the require config files, this is what they looked like:

require.config({
    "packages": [
        {   
            "name": "jquery",
            "location": "lib/jquery",
            "main": "dist/jquery.js"
        }   
    ],  
    "shim": {}
});

Notice the "location" : "lib/jquery". What I wanted this to be was /js/lib/jquery.

This change adds an option locationBase (might not be the best name...), which is then appended to the location, resulting in:

// package.json
"jam": {
    "packageDir": "public/js/lib",
    "baseUrl": "public/js",
    "locationBase": "/js",
    "dependencies": {
        "jquery": "1.8.3"
    }
}

// require.js
require.config({
    "packages": [
        {   
            "name": "jquery",
            "location": "/js/lib/jquery",
            "main": "dist/jquery.js"
        }   
    ],  
    "shim": {}
});

I setup the tests and ran them after making the change and only got one failure:

jam-tests

I dont think that has anything to do with the changes, but let me know if I am wrong...

Anyway, good work on the package manager!!

@wesleytodd wesleytodd Possible solution for absolute paths
- Added `locationBase` option which is used to prefix the script location
- Updated rebuild command to pass the base into `updateRequireConfig` method
- Updated `updateRequireConfig` to prefix the location with the optional `locationBase`
51e8f6c

The solution I found here works great, just adding:

require.config({
    baseUrl: '/my/absolute/path'
});

I feel like it would be nice to see something built in to Jam to handle this so I didn't have to add this for every project. Or maybe just documenting this other way to shorten the learning curve?

Also, my above pull request is obviously not the best way to do this now that I have worked a bit more with require and jam, so please disregard it...

wesleytodd closed this Feb 16, 2013

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