node-build-script
node-build-script copied to clipboard
[JS] Uncaught ReferenceError: define is not defined
Hello!
I'm currently having this issue when concatenating my JS scripts. The original ones do not have this error, and this happens only with the "[HASH]-main.js" file. The error is "Uncaught ReferenceError: define is not defined ", and the problem is in the very end of the script:
,define("main",[],function(){})
is being added. Live issue (till fix ^^) http://gearmakeup.com/
Hello!
I would need to see your whole configuration file. Can you create a gist (even private) where you would copy-paste your whole Gruntfile?
I suspect this because require.js (or almond) is not included in your optimized file, and that when define("main",[],function(){})
is parsed / executed, define is undefined.
Yes, require.js is not in there (P.S. I've deleted the last define for testing purposes from the publish dir)... I think I've messed with the creation of the project, but there was really little documentation (don't misunderstand me, for people knowing what require.js is, it's self-explanatory). How can I fix that? As you may already know, I'm currently loading several js files, does require.js allow me to include a single one?
Thanks
ohh, you can turn it into "The creation of the project messed with you" :) Not necessarily your fault, as you said the documentation on rjs support is very poor for the build script.
See my comment here, the rjs configuration can be changed to work on a single file optim mode. I found that for most of the cases, when we optimize for a single file, the single file way of doing it is far better / simpler (and the whole project optimization of rjs somewhat conflicts a bit with what the build script provides).
require.js is usually used while you're in development, where all of your files are pulled in individually by require.js at runtime. For prod, when you trigger a build, all your application files should be compiled down to a single optimized file by the requirejs optimizer.
You can also play with the concat
task in your gruntfile (which is overridden as a noop when rjs is enabled), to enable it back and manually concat your require.js library file (or almond if you can use it) with the output of the rjs
task. concat
would need to run right after the rjs
task.
Or maybe you would opt for two optimized file, one for all your library / plugins / etc. and one for your application code. require.js script would go into your library optimized file (along jQuery or other dependency). I find myself using this a lot.
BTW I played once with the h5bp exec and it rosted my JS original files, what a mess! Fortunatelly I knew what I wrote and, beautifying the code again, I was able to restore them (yes, blame me for not using control-version systems :) ).
Are you saying the builder is able to parse the require.js file and thus substutute that with a single-generated file? Or just configure the grunt.js file just like the css parameter? (i.e. css: { 'file.css': ['onefile.css', 'anotherfile.css'] } ? Or both? (i.e. configure grunt to make one javascript and then it will automatically substitute the require.js with the actual one?)
Thanks :)