requirejs / almond

A minimal AMD API implementation for use after optimized builds
Other
2.42k stars 168 forks source link

How to get r.js optimiser to insert define module IDs? #91

Closed citizenmatt closed 9 years ago

citizenmatt commented 10 years ago

The readme states that the RequireJS optimiser will automatically add module IDs for define calls that don't provide one, when concatenating into a single file. However, I can't get this to work. I'm trying to create a single file from several files that use anonymous defines, with almond, and while it concatenates everything correctly, the anonymous defines are not fixed up and replaced with the module ID. Am I doing something wrong?

I'm using the Emmet project with the config defined in [Gruntfile.js](https://github.com/emmetio/emmet/blob/master/Gruntfile.js#L34-L51). Or, by using the following (mostly equivalent) build.js:

({
    baseUrl: './lib',
    paths: {
        lodash: '../node_modules/lodash/lodash'
    },
    out: './foo.js',
    include: ['./emmet'],
    optimize: 'none'
})

Am I missing something? Should the defines be replaced?

stephanebachelier commented 10 years ago

@citizenmatt I think it should be post in r.js repo

As you can notice here almond does not know how to use anonymous module

citizenmatt commented 10 years ago

Yeah, I saw that, but in the "Restrictions" section, it also says:

All modules [must] have IDs and dependency arrays in their define() calls -- the RequireJS optimizer will take care of this for you.

Since this is specifically called out, I thought here would be a good place with advice on how to achieve it. I'll try the r.js repo, though. Thanks!

citizenmatt commented 10 years ago

I've added an issue for r.js - jrburke/r.js#733

jrburke commented 9 years ago

Closing in favor of tracking in jrburke/r.js#733.