requirejs / requirejs

A file and module loader for JavaScript
https://requirejs.org/
Other
12.95k stars 2.37k forks source link

config.bundles can't use config.map values #1429

Closed ORESoftware closed 8 years ago

ORESoftware commented 9 years ago

As far as I can tell, map values are not being referenced in bundles values in requirejs.config({})

if I have this:

 map: {
        '*': {
            'REACT_VIEWS_BASE': 'app/js/jsx/reactComponents',
            'STANDARD_VIEWS_BASE': 'app/js/jsx/allStandardViews',
            'TEMPLATES_BASE':'text!app/templates'
        }
    },

and I have this:

   bundles: {
        'app/optimized/bundles/DashboardView': [
            'STANDARD_VIEWS_BASE/DashboardView',
            'REACT_VIEWS_BASE/ServiceChooser',
            'REACT_VIEWS_BASE/Service',
            'TEMPLATES_BASE/dashboardTemplate.ejs'
        ],
        'app/optimized/bundles/JobsView': [
            'app/js/jsx/relViews/jobs/jobsView',
            'REACT_VIEWS_BASE/JobsList',
            'REACT_VIEWS_BASE/Job',
            'TEMPLATES_BASE/jobsTemplate.ejs'
        ],
        'app/optimized/bundles/OverView': [
            'STANDARD_VIEWS_BASE/OverviewView',
            'REACT_VIEWS_BASE/RealTimeSearchView',
            'TEMPLATES_BASE/overviewTemplate.ejs'
        ],
        'app/optimized/bundles/UserProfile': [
            'STANDARD_VIEWS_BASE/UserProfileView',
            'TEMPLATES_BASE/userProfileTemplate.ejs'
        ]
    },

it doesn't work as expected, and it seems clear that the values from map are not being used to evaluate the strings in bundles (I guess, why should they?). Shouldn't map take precedence over bundles and subsequently referenced in bundles?

It could be that map is only referenced in require and define, but why not bundles too? I can confirm that map values are successfully referenced in the include option in build config files, such as so:

  HomeAndIndexView: _.extendOwn({}, baseConfig, {
            "out": "./public/static/app/optimized/bundles/HomeAndIndexView.js",
            "include": [
                'STANDARD_VIEWS_BASE/HomeView',
                'REACT_VIEWS_BASE/TimerExample',
                'STANDARD_VIEWS_BASE/PortalView',
                'REACT_VIEWS_BASE/MenuExample',
                'STANDARD_VIEWS_BASE/HeaderView',
                'STANDARD_VIEWS_BASE/FooterView',
                'STANDARD_VIEWS_BASE/RegisteredUsersView',
                'STANDARD_VIEWS_BASE/LoginView',
                'STANDARD_VIEWS_BASE/IndexView'

            ]
        }),
jrburke commented 8 years ago

It gets confusing if some properties at the top level should or should not use map: if some do and some do not it will be hard to trace how things bottom out to final IDs. The goal with configuration should be to work on final, resolved, absolute module IDs.