Frage

I am trying to get browserify-shim to work, but I can't seem to get it to create the globals I expect to see.

(note, my end goal is to get this working from gulp, but after having many problems, I figured I would eliminate one variable and try to get this working in browserify alone)

In this case, I expect "horses" to be created as a global variable pointing to the jQuery library.

// package.json

{
  "version": "0.0.1",
  "browser": {
    "jquery": "./lib/js/vendor/jquery-2.0.2.js"
  },
  "browserify": {
    "transform": [
      "browserify-shim"
    ]
  },
  "browserify-shim": {
    "jquery": "global:horses"
  },
  "devDependencies": {
    // my dev dependencies
  },
  "dependencies": {
    // my production dependencies
  }
}

With this configuration, from the command line I run:

browserify common.js > mycoolfile.js

I then include mycoolfile.js into my application and run it in the browser:

<script src="mycoolfile.js"></script>

The browserified file is included fine, but when I go to chrome dev tools console and type "horses" I get an undefined error. Any thoughts on what I may be doing wrong? Thank you

War es hilfreich?

Lösung

I think that you want to get at jquery via exports and you are also assuming that global lets you take a global a module creates and make an alias for it, but I don't think it does that. The above might work if jquery really did have a global called horses it creates, but it won't if you just make up that name arbitrarily. I think you are trying to do something more like this:

"browserify-shim": {
  "jquery": {"exports": "jQuery"}
},
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top