Skip to content
This repository was archived by the owner on Aug 7, 2019. It is now read-only.

Conversation

@maxpeterson
Copy link
Contributor

This is the same issue as caolan/jam/#113 with the addition of a test.

Issue: the compile command currently doesn't include shim config the project is using, so optimized output breaks
Solution: include shim config from jam/require.config.js in the optimize call

The crux of this issue is that if you use shim to define that a package exports a variable (e.g. Backbone or in mytest PackageOne) then this shim is needed by require's optimiser to defines the package such that it returns the exported variable.

My test includes a module with main.js:

var PackageOne = {
    name: 'Package One'
}

and package.js:

{
    "name": "package-one",
    "version": "0.0.1",
    "description": "Test package one shim",
    "jam": {
        "shim": {
            "exports": "PackageOne"
        }
    }
}

If the shim is not passed to the optimiser then it will define package-one/main as:

define("package-one/main",function(){})

If shim is passed to the optimiser then it will define package-one/main as:

define("package-one/main",function(e){return function(){var t,n;return t||e.PackageOne}}(this));

In both cases package-one is defined as

define("package-one",["package-one/main"],function(e){return e})

The result is that without the shim any package that requires package-one as a dependency will not get passed PackageOne:

define('mypackage', ['package-one'], function (one) { 
   //  one will only be defined as PackageOne if shim is included
}

In addition I fixed some typos in the other integration tests,

@maxpeterson
Copy link
Contributor Author

@caolan have you had a chance to look at this? It is blocking us from using jam compile to build our projects. We are using requires r.js -o app.build.js with app.build.js packages and shim copied from jam/require.config.js.

If there is anything I can do let me know.

@copenhas
Copy link

I'm running into the same problem right now actually with the added issue of I need to supply extra shim configuration. It would appear that the require.config.js for jam gets regenerated and is not a safe place to do this so I have a separate file that specifies our additional shim info.

Again, in a non-optimized site it works fine, but once you run everything through jam compile it breaks.

@maxpeterson
Copy link
Contributor Author

@copenhas you can usually put the shim in the package.js. Have you tested with this branch. The only change you actually need for the fix is in lib/commands/compile.js, the rest is tests.

@copenhas
Copy link

@maxpeterson I haven't tested with this branch. I've been fighting this issue for a little over a day and once I knew what was happening I started searching. Great to see that the exact issue is trying to be resolved, but at the moment I need to get this working and will probably resort to globals temporarily.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants