caolan / jam

JavaScript package manager - using a browser-focused and RequireJS compatible repository
MIT License
1.5k stars 105 forks source link

Absolute base URL #143

Open BrianHicks opened 11 years ago

BrianHicks commented 11 years ago

(disclaimer: I'm a bit new to both Jam and require, trying to figure this out for the first time.)

I'm using Jam with Django. Right now, here's the relevant bits of my package.json:

{
    "jam": {
        "packageDir": "assets",
        "baseUrl": "static",
        "dependencies": {
            "bootstrap": "2.3.1",
            "jquery": "2.0.0",
            "angularjs": "1.0.5",
            "angular-resource": "1.0.1"
        }
    }
}

This makes Jam calculate the paths of the assets as (for example) ../assets/angularjs. What I expected (and in fact need here) is for the path to look like /static/angularjs. (The reasons for this are slightly wonky. Django handles static files by copying them from a different directory in production, and serving them as if they were already copied in development.)

If it's not possible in some way to change this, is there a flag I can set to have Jam leave my require.js and require.config.js alone on installs so I can set the paths manually?

Jae commented 11 years ago

the module managed by Jam needs to be accessible via url as it's loaded asynchronously by require.js. without changing Jam what you could do is to have packageDir to be "assets/static" and baseUrl to be "assets" which will generate your paths to be "static/angularjs". Then in your app.js you could set the baseUrl to be '/' which will give you the right path "/static/angularjs". obviously you would need to have something setup during development to serve "/static/angularjs" from "assets/static/angularjs". you can compile it everything into one js file for production via build pipeline.