So, I tried to set an empty directory with the following files and folders
/grunt.js /src/js/main.js /tmp/js
Here is my grunt.js:
module.exports = function(grunt) { grunt.loadNpmTasks("grunt-requirejs"); grunt.initConfig({ requirejs: { dist: { options: { almond: true, wrap: true, modules: [{name: 'main'}], mainConfigFile: "src/js/main.js", baseUrl: "src/js", dir: "tmp/js", inlineText: true, preserveLicenseComments: false } } } }); grunt.registerTask("default", "requirejs"); };
Here is my main.js:
define(function() { console.log('hi'); });
I ran these commands in the console:
npm install grunt npm install requirejs npm install grunt-requirejs grunt --gruntfile grunt.js
Make a conclusion:
Running "requirejs:dist" (requirejs) task >> RequireJS optimizer finished Uncompressed size: 14234 bytes. Compressed size: 1265 bytes gzipped. (2633 bytes minified)
The resulting file in /tmp/js/main.js had links to almonds. He did not mention the definition function, although due to the minimization of js. My call to define( been rewritten to n( .
I suspect that you might have code outside the collapsed file that calls define.
Also, in my other project, mainConfigFile is referenced only as a configuration file and not loaded as a module.
David hogue
source share