2

My source browserify coffeeify file:

$ = jQuery = require 'jquery'
require 'jq-ui'
$ ->
    jqueryUiIsLoaded = jQuery.ui
    console.log "jquery-ui is loaded: #{jqueryUiIsLoaded}"

which I convert to main.js with command:

browserify source.coffee -t coffeeify > main.js --debug

My package.json:

{
  "name": "jquery_ui_test",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "main": "browserify source.coffee -t coffeeify > main.js --debug"
  },
  "browser": {
    "jquery": "./node_modules/jquery/dist/jquery.min.js",
    "jq-ui": "./node_modules/jquery-ui/jquery-ui.js"
  },
  "browserify-shim": {
    "jquery": "$",
    "jq-ui": {
      "exports": "jq-ui",
      "depends": [
        "jquery:jQuery"
      ]
    }
  },
  "dependencies": {
    "coffee-script": "*"
  },
  "devDependencies": {
    "browserify": "^6.0.2",
    "coffeeify": "^0.7.0",
    "jquery": "^2.1.1",
    "jquery-ui": "^1.10.5"
  }
}

My html:

<html>
<head>
    <script src='./main.js'/>
</head>
</html>

In browser console I see that jquery ui is not loaded:

jquery-ui is loaded: undefined source.coffee:5

What should I do to make jquery-ui load with browserify?

1
  • Did you ever get this to work without using Bower? Commented Nov 17, 2015 at 4:13

1 Answer 1

1

The solution was in using debowerify: I installed jquery and jquery-ui via bower. My package.json is:

{
  "name": "jquery_ui_test",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "main": "browserify source.coffee -t coffeeify -t debowerify > main.js --debug"
  },
  "dependencies": {
    "coffee-script": "*"
  },
  "devDependencies": {
    "browserify": "<6",
    "coffeeify": "^0.7.0",
    "debowerify": "^0.8.2"
  }
}

My source.coffee is :

$ = window.jQuery = require("jquery")
require "jquery-ui"
jqueryUiIsLoaded = jQuery.ui
console.log "jquery-ui is loaded: #{jqueryUiIsLoaded}"

And browser console output is:

jquery-ui is loaded: [object Object]

So jquery-ui is working.

Sign up to request clarification or add additional context in comments.

4 Comments

So how do you load for example just the autocomplete without it loading the whole library?
I don't think it is possible to load autocomplete without the whole jquery ui, isn't it?
Normally you can pick and choose what gets included... jqueryui.com/download
@IanWarburton nice to know. I this case debowefy will not help you or you can work around by replacing ./bower_components/jquery-ui/jquery-ui.js by your cutted version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.