Code Monkey home page Code Monkey logo

Comments (7)

gfranko avatar gfranko commented on August 18, 2024

If you are using the RequireJS optimizer Grunt task, then it is very easy to integrate amdclean using the onBuildWrite config option. Here is an example Grunt file that includes the RequireJS optimizer plugin with amdclean support:

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    requirejs: {
      js: {
        options: {
          findNestedDependencies: true,
          baseUrl: 'src/js/app/modules',
          wrap: true,
          preserveLicenseComments: false,
          optimize: 'none',
          mainConfigFile: 'src/js/app/config/config.js',
          include: ['first'],
          out: 'src/js/app/exampleLib.js',
          onBuildWrite: function( name, path, contents ) {
            return require('amdclean').clean(contents);
          }
        }
      }
    }
  });
  grunt.loadNpmTasks('grunt-contrib-requirejs');
  grunt.registerTask('build', ['requirejs:js']);
  grunt.registerTask('default', ['build']);
};

from amdclean.

binarykitchen avatar binarykitchen commented on August 18, 2024

Cool, thx for the fast response. You might want to add that in the README for others.

Anyway, it is still not working for me. With the grunt config of mine I get an error:

$ grunt requirejs
Running "requirejs:js" (requirejs) task
>> Tracing dependencies for: main
[Error: Error: Error: Not a unique module name: jade
Fix: Make sure that you assign unique module paths using the require.config() method.  Take a look at http://requirejs.org/docs/api.html#config for more details
Result: Did not complete and exiting...
    at Object.utils.hasUniqueModuleName (/xxx/node_modules/amdclean/src/amdclean.js:90:35)
]

Here is my config, inspired by you:

    requirejs: {
      js: {
        options: {
          findNestedDependencies: true,
          baseUrl: "client/scripts",
          name: 'main',
          mainConfigFile: "client/scripts/config/require.config.js",
          out: "server/public/scripts/main.min.js",
          useStrict: true,
          preserveLicenseComments: false,
          optimize: 'uglify2',
          pragmasOnSave: {
            excludeJade : true // remove jade compiler, se https://github.com/deedubs/require-jade
          },
          onBuildWrite: function( name, path, contents ) {
            return require('amdclean').clean(contents);
          }
        }
      }

In my require.config.js I have declared the path for jade and it works fine.

from amdclean.

gfranko avatar gfranko commented on August 18, 2024

Good call with adding the Grunt information to the README, I'll add it tonight. That error message says that you have more than one module with the same name. Could you send the full source of your library un-minified (just comment out the amdclean for now).

from amdclean.

binarykitchen avatar binarykitchen commented on August 18, 2024

Ok, have sent the source code to your inbox. Do not want to publish it. Hope you can find the problem?

from amdclean.

gfranko avatar gfranko commented on August 18, 2024

Okay, so jade is declared twice:

define('jade', jade);


define('jade',{
        version: '0.0.3',
    load: function (name, parentRequire, load, config) {

    }
});

Also, amdclean doesn't support AMD module loader plugins. I think almond.js would be a better fit for your use case.

from amdclean.

binarykitchen avatar binarykitchen commented on August 18, 2024

Oh I see. Thanks a lot for your honesty and help. Great response.

All the best!

from amdclean.

gfranko avatar gfranko commented on August 18, 2024

@binarykitchen AMDClean is now a much more mature project and should work for you.

from amdclean.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.