Jquery module not found with grunt-browsify

My app config includes:

package.json

{
  "name": "myapp",
  "version": "0.0.1",
  "scripts": {
    "start": "node app"
  },
  "repository": {
    "type": "git",
    "url": "git@github.com:me/myapp"
  },
  "dependencies": {
    "browserify": "^5.10.1",
    "browserify-shim": "^3.7.0",
    "grunt-browserify": "^2.1.4",
  },
  "engines": {
    "node": "0.10.x"
  },
  "browser": {
    "jquery": "public/bower_components/jquery/dist/jquery.min.js"
  },
  "browserify-shim": {
    "jquery": { "exports": "$" }
  },
  "browserify": {
    "transform": [
      "browserify-shim"
    ]
  }
}

      

Gruntfile.js

module.exports = function(grunt) {
    grunt.initConfig({
        browserify: {
            app: {
                src: [ 'public/javascripts/app.js' ],
                dest: 'public/javascripts/build.js'
            }
        }
    });

    grunt.loadNpmTasks('grunt-browserify');
    grunt.registerTask('default', ['browserify']);
};

      

public /JavaScripts/app.js

var $ = require('jquery');

$(document).ready(function() {
    alert('Ciao!');
});

      

Result:

Run task "browser: app" (scroll) Error: module "jquery" not found from "/Users/me/GitHub/myapp/public/javascripts/app.js"

I found similar configuration examples on the internet, I cannot find my error, please help me! I just want to use grunt and browserify in my project. The next step is to enable twitter bootstrap.

BTW, I don't want to install the jquery npm module, I want to use the gazebo.

+3


source to share


1 answer


Are you trying to use debowerify ? If you are using debowerify your package.json will be simplified like this:

package.json



{
  "name": "myapp",
  "version": "0.0.1",
  "scripts": {
    "start": "node app"
  },
  "repository": {
    "type": "git",
    "url": "git@github.com:me/myapp"
  },
  "dependencies": {
    "debowerify": "^0.8.1",
    "grunt": "^0.4.5",
    "grunt-browserify": "^3.0.1",
  },
  "engines": {
    "node": "0.10.x"
  },
  "browserify": {
    "transform": [
      "debowerify"
    ]
  }
}

      

Gruntfile.js and public / javascripts / app.js may still be the same as above

+1


source







All Articles