Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow loader config in file(s) #493

Closed
ghost opened this issue Sep 15, 2015 · 2 comments
Closed

Allow loader config in file(s) #493

ghost opened this issue Sep 15, 2015 · 2 comments
Labels
enhancement A new or improved feature needs-opinions Needs opinions to decide how to handle

Comments

@ghost
Copy link

ghost commented Sep 15, 2015

It would be helpful if I could allow to specify the AMD loader config by pointing to a file[1] which contains require.config call itself, not only via inline loaderOptions. This is how, for example, RequireJS optimizer allows to specify the config.


[1] In fact, I would like to be able to specify list of files - I've got config.js for production and config-test.js with additional pieces of AMD config in a seperate config file. For now, I must use the ugly workaround, having this in separate file config-all-options.js:

// Take config.js and config-test.js from root and extract
// just the options passed to require.config, merged.

define(['../../bower_components/lodash-compat/lodash', 'intern/dojo/text!config.js', 'intern/dojo/text!config-test.js'], function (_, configJs, testConfigJs) {
var options = {};
(function (require) {
eval(configJs);
eval(testConfigJs);
})({
config: function (x) {
options = _.merge(options, x);
}
});
return options;
});
``` and define intern config as:

```js
define(['./support/config-all-options'], function (options) {
return {
/// ...
loaderOptions: options,
/// ...
}
});
@csnover csnover added enhancement A new or improved feature needs-opinions Needs opinions to decide how to handle labels Sep 18, 2015
@sholladay
Copy link
Contributor

Personally, I've always hated how the RequireJS optimizer scans a file for a require.config() call and parses its argument. It feels very hacky to me. And that whole paradigm is poisonous, since it leads to feature requests like this across many projects.

What I do is define all of my AMD configuration in a real module that can be read by any tooling that can consume that module. Then, during my build process, any nonsense like require.config() is simply constructed and written to disk wherever it is needed. This setup is more flexible, maintainable, and declarative. Because this has treated me well, my vote is to avoid parsing like this.

Basically, I'm suggesting to think from the other direction and treat require.config() as a special case, where your config needs to be serialized for the client. Once you get into that mindset, you regain all of the usual benefits of real modules, which the RequireJS optimizer really should not have stolen from you in the first place.

@jason0x43
Copy link
Member

Intern's configuration system is quite different now, and an external loader is no longer required when running on Node (assuming your code and suites are CommonJS). You can use multiple config files, or multiple config profiles in a single config file, to hold different loader configs. You could also load a config module as a plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new or improved feature needs-opinions Needs opinions to decide how to handle
Projects
None yet
Development

No branches or pull requests

3 participants