Optimizer Require.js and variables in paths

I have a problem with r.js working the way we need.

I have the following problem: we have 2 domains (e.g. foo.de and bar.de) and different environments. Depending on which environment and domain they are working in, you need to download another file from the source servers. My initial solution was the following:

// channelDomain and environmentPath get defined above this script require.config({ paths: { 'fooscript': channelDomain+environmentPath } } 

Testing this in an unoptimized browser works exactly as it should , but the nightly build complained:

 [Error: Error: The config in mainConfigFile /absolute/path/app/public/js/main.js cannot be used because it cannot be evaluated correctly while running in the optimizer. Try only using a config that is also valid JSON, or do not use mainConfigFile and instead copy the config values needed into a build file or command line arguments given to the optimizer. Source error from parsing: /absolute/path/app/public/js/main.js: ReferenceError: channelDomain is not defined 

I tried to do many things, but my ideas are running out. I tried to make it empty: a thing in the build file, but that didn't work either. I would be glad if someone could point me in the right direction.

+4
source share
1 answer

Use two require.config files in the same file. The optimizer will only read the first one, as James says here https://github.com/jrburke/r.js/issues/270#issuecomment-13112859 , and it will work in the browser after optimization.

So in the end you will have something like this in main.js:

 require.config({ //only configurations needed for the transpiler optimization }); require.config({ paths: { 'fooscript': channelDomain+environmentPath } }); 
+2
source

Source: https://habr.com/ru/post/1499099/


All Articles