As the title says my inline require calls are working in a non-optimized requirejs run but not working when built with grunt and almondjs.
Uncaught Error: undefined missing views/some/view
The top of any file might be:
define(
['jquery', 'app'],
function($, App) {
and later on based on business logic I want to be able to require another file
require(['views/some/view'], function(SomeView){
console.log(SomeView);
});
I tried the alternative syntax as well:
var SomeView= require('views/some/view');
And this all works using an unbuilt requirejs version. But again it fails when I build it with grunt and almond
requirejs: {
compile: {
options: {
name: "../components/almond/almond",
baseUrl: "src",
mainConfigFile: "./require.config.js",
include: ['main'],
insertRequire: ['main'], // Add a require step in at the end for the main module.
wrap: true, // Wrap everything up in a closure
generateSourceMaps: true, // Experimental
preserveLicenseComments: false, // Needs turned off for generateSourceMaps
optimize: "uglify2", // Supports generateSourceMaps
out: "assets/javascripts/build.js"
}
}
},
I can get it working fine in almond if I put it up at the top of the file in a define call, but isn't it preferable in AMD to keep it lean?
According to the Almond documentation it works best with non-dynamic loading and everything packaged into the one file.
You should be able to set "findNestedDependencies" to true in your compile options to ensure that your inline require calls are included as part of the build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With