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
I want to dynamically create a main.js file which will contain the requirejs config. #1794
Comments
You can generate that file on the fly using for e.g. NodeJS or PHP. You can even create a static file which will just contains the shim and paths config. After loading it you can dynamically load modules which are required on current page |
Thanks for the response @ddziaduch . |
Sorry, I do not understand, can you please explain? |
As you can see, 'Application' is moduleId/module name of this file where 'Home', 'Details' and 'AboutUs' are the moduleid/module name of their respective files. So when i try to optimize this, requirejs optimizer should load all the dpendency of this 'Application' file i.e 'Home', 'Details' and 'AbotUs'. But it doesn't do that, means it completely stops optimizing other files and just optimize only this file with loading its dependecies. |
@sohankd can you please show your file tree and your config file? |
Ah that is the correct behaviour. When you assign the Modue ID it will not work because RequireJS doesn't know where the module is in placed in the file tree. So there are two options:
|
Thanks. Last question. Is there any way which can notify me that all the modules are loaded,so that i can call a module from those modules to start the application ? |
@sohankd just add modules as dependencies, so RequireJS will execute the callback after all modules load 🙂 |
@ddziaduch thanks. I know this one. But what if i want to make the call in index.html file instead of a require call in mainConfig file. Will require('Application') be enough to start the application,declared in index.html file ? `/* mainConfig.js */ /* Index.html */ <script>var app = require('Application');app(); // i want to start from here. |
It won't work like that because |
@ddziaduch Thanks for the help. |
@ddziaduch Hello. I tried how you suggested me, but that didn't work.I assigned moduleID to every module and also specified path for them in config file.But its still not loading the files mentioned in 'paths'. It only makes a require call to 'Application' which also fails. |
What does this optimization process do? |
@ddziaduch It gethers all the files defined in 'path' property of config file and minify them to one file. |
@sohankd so it should work - your code looks valid 🙂 |
@ddziaduch thanks. I solved it. |
@sohankd what was the issue? |
@ddziaduch one is baseUrl, and we have to set the mainConfigFile property to point to config.js file. thats it. Thanks for your help. |
I have a json file where i list out all the modules that i want to use in my app and bundle them. So for that i haven't created a main.js file, but i want to create that file dynamically and want to add the paths, shims and other configs dynamically too. So how can i achieve that ? Or is there any way where i can extend the prebuilt config of main.js file and those extra modules
Here is my json file which conatins the module paths.
custom-package.json
`{
"name": "custom-package,
"modulePaths:{
"modules": "src/modules"
"vendor": "src/vendor"
}
"modules": [
"modules/Application"
"modules/Home"
"modules/AboutUs"
"vendor/Backbone"
"vendor/jquery"
]
}`
The text was updated successfully, but these errors were encountered: