Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8626411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:01:40+00:00 2026-06-12T08:01:40+00:00

I am currently working myself into requirejs, to do this I started to write

  • 0

I am currently working myself into requirejs, to do this I started to write a small package. The package consists of one main.js, the entry point for the application and several other modules that will be loaded into main.js through a call to require.

The package has several options that can be configured during runtime, to ease maintenance I have a central configuration.js that is loaded whenever needed. The contents of configuration.js is just an object that maps key to value, no functionality or anything. Just a key-value map.

Now requirejs allows to pass options to packages, the configuration is done through the requirejs config. The problem I have is, that it is only available in the main.js and not in other modules in the package, also I could not find a way to set default values unless I hardcode them into the main.js.

My current approach (the one with the configuration.js) is to merge the configuration given to requirejs with the contents of my configuration.js in the main.js.

main.js

define(function(require, exports, module) {
    var $ = require('jquery'); // Could be any library that offers an "extend"
                               // feature that allows "deep" copies.

    var config = require('configuration'); // Load configuration file

    $.extend(true, config, module.config()); // Overwrite default values with 
                                             // set values


    var otherfile = require('anyotherfile);
    otherfile();
});

anyotherfile.js

define(function(require, exports, module) {
    var config = require('config'); // Loads configuration, package-wide
                                    // options are set

    // module.config() will be empty. Unless I explicicy specify the
    // configuration for this one module in the "requirejs.config"

    return function() {
        // Something that can be configured
    };
});

This way of setting configuration options makes me dependent on an additional library or my own implementation of an extend functionality (it’s not much code, but still more code than no code) plus there are two points where I have to look for possible configuration mistakes which makes it harder to find errors.

So now I am searching for a better way to pass a package-wide configuration all while trying to avoid more than one point of failure. (This might be hard cause somewhere I have to store the default values if I don’t want to hardcode them.) And of course the solution should not depend on any additional libraries or my own extend functionality.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:01:41+00:00Added an answer on June 12, 2026 at 8:01 am

    After talking with jrburke about the problem the best solution is to do the extending of the config array in the configuration.js.

    Example of the file configuration.js

    define(function(require, exports, module) {
        var $ = require('jquery'); // need jQuery for extend
        var config = {
            key: value,
            ...
        };
        return $.extend(true, config, module.config());
    });
    

    So there is no more need to do this in the main.js.

    The only disadvantage of this approach is that in the requirejs.config you have to address
    package/configuration and not package.

    Example of the requirejs.config

    requirejs.config({
        config: {
            "package/configuration": {
                 key: value
            }
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently working with the following package structure: /package __init__.py final.py /write __init__.py write.py /data
Currently working with converting SQLException error messages into messages that are more useful for
I have just started working with a new company in a very small IT
Im currently working on a c# project that uses another .net library. This library
a former coworker (artist) and myself (programmer) are currently developing a small game together
today i started reading myself into the features of Zend\Form. I found a great
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I am currently working on a little program for myself, connected to LastFM. Here
I'm currently working on a project (that's almost done :D) but I've run into
The Background I am currently working on small MIPS program for a homework assignment,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.