You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is a bit hard to follow that the core issue is since it is unclear what loader plugin is being used and how it is failing in the build. Loader plugins can participate in the build, even specifying a separate "plubinBuilder" module to be run just in the builds, but the API it is not the greatest or well explained. It might be worth looking at the text plugin to see how it interacts with the build system.
If I leave out the typeof window !== "undefined" in my define (/* 2 */), the plugin will try to run the dependencies during build time, causing errors to occur from running code on a server that's supposed to be run in a browser.
Adding the typeof window !== "undefined", however, causes r.js not to recognize this code as a module, adding a empty define("full/path/to/ModuleA", [], function () {} module at the end and breaking my bundle when trying to run it in the browser. Using a named module (/* 1 */) fixes this.
The typeof window !== "undefined" in my load method (/* 3 */) is also necessary to prevent code from code running on a server that's supposed to be run in a browser (like doing an Ajax call to check for availability of a file
Adding my dependencies again at /* 4 */ was necessary to ensure they're included after leaving them out in the define. I could not use relative paths here because inside the bundle those paths would be evaluated as relative to the bundle rather than the module.
Anyway, I just learnt that our Jenkins build breaks because of the changes I made to make these modules work nicely with r.js, so it's not just a cosmetic improvement I'm looking for.
Activity
jrburke commentedon May 21, 2018
It is a bit hard to follow that the core issue is since it is unclear what loader plugin is being used and how it is failing in the build. Loader plugins can participate in the build, even specifying a separate "plubinBuilder" module to be run just in the builds, but the API it is not the greatest or well explained. It might be worth looking at the text plugin to see how it interacts with the build system.
jslegers commentedon May 22, 2018
There are four core issues here :
typeof window !== "undefined"in mydefine(/* 2 */), the plugin will try to run the dependencies during build time, causing errors to occur from running code on a server that's supposed to be run in a browser.typeof window !== "undefined", however, causes r.js not to recognize this code as a module, adding a emptydefine("full/path/to/ModuleA", [], function () {}module at the end and breaking my bundle when trying to run it in the browser. Using a named module (/* 1 */) fixes this.typeof window !== "undefined"in my load method (/* 3 */) is also necessary to prevent code from code running on a server that's supposed to be run in a browser (like doing an Ajax call to check for availability of a file/* 4 */was necessary to ensure they're included after leaving them out in thedefine. I could not use relative paths here because inside the bundle those paths would be evaluated as relative to the bundle rather than the module.Anyway, I just learnt that our Jenkins build breaks because of the changes I made to make these modules work nicely with r.js, so it's not just a cosmetic improvement I'm looking for.
memoryseven commentedon Jan 18, 2019
"full/path/to/ModuleA" is an exists module?
jslegers commentedon Jan 18, 2019
"full/path/to/ModuleA" is the full path to the module I'm defining here.