gulp-browserify icon indicating copy to clipboard operation
gulp-browserify copied to clipboard

Upgrade to browserify-shim v3 API

Open JHKennedy4 opened this issue 11 years ago • 13 comments

Allows support for shimming libraries loaded via cdn, would also allow you to reference their current docs.

JHKennedy4 avatar Feb 12 '14 06:02 JHKennedy4

@shuhei can we drop support for shim and allow using via transforms ?

deepak1556 avatar Feb 12 '14 07:02 deepak1556

@deepak1556 Yeah, it would be nice to deprecate it first showing warning and drop it later.

shuhei avatar Feb 12 '14 12:02 shuhei

Does the browserify-shim transform currently work? Is there an example how to configure it?

jgrowl avatar Feb 13 '14 03:02 jgrowl

@jgrowl there is an example in #48 by @shuhei , will doc in readme soon.

deepak1556 avatar Feb 13 '14 05:02 deepak1556

@jgrowl This plugin does nothing to transforms. See browserify-shim's README for examples.

shuhei avatar Feb 13 '14 05:02 shuhei

@shuhei @deepak1556 Ahh, thanks. I was getting thrown off because when I added "browserify-shim" to my transforms in my gulpfile I was getting Error: browserify-shim needs to be passed a proper browserify instance as the first argument.

If I add the configuration purely in the package.json file, all seems good.

jgrowl avatar Feb 13 '14 16:02 jgrowl

Just to make it clear for future reference:

  1. Install browserify-shim (npm install --save-dev browserify-shim)
  2. Put all config in package.json. See browserify-shim's README for examples.
  3. Register the transform with gulp-browserify (transform: ['browserify-shim'])

gaastonsr avatar Feb 14 '14 02:02 gaastonsr

Thanks! On Feb 13, 2014 9:14 PM, "gaastonsr" [email protected] wrote:

Just to make it clear for future reference:

  1. Install browserify-shim (npm install --save-dev browserify-shim)
  2. Put all config in package.json. See browserify-shim's READMEhttps://github.com/thlorenz/browserify-shimfor examples.
  3. Register the transform with gulp-browserify (transform: ['browserify-shim'])

Reply to this email directly or view it on GitHubhttps://github.com/deepak1556/gulp-browserify/issues/53#issuecomment-35049389 .

JHKennedy4 avatar Feb 14 '14 17:02 JHKennedy4

Hi, every body! I'm tying to use browserify-shim with karma and encounter such error: Error: browserify-shim needs to be passed a proper browserify instance as the first argument.

The same thing I've got when use broserify from command line. Here is my package.json part:

"browserify": {
        "transform": [ "browserify-shim" ]
},
"browser": {
        "jquery"    :  "./client/requires/jquery/js/jquery.js",
        "bootstrap" :  "./client/requires/bootstrap/bootstrap.js"
},
"browserify-shim": {
        "jquery"    :  "$",
        "bootstrap" :  {"exports": null, "depends": [ "jquery" ] 
}

my file mainSpec.js to be browserifed looks this way:

...
var someModule = require('path/to/module');
require('bootstrap');
...

then in command line $ broserify mainSpec.js -o bundleSpec.js I use browserify v 2.36.1 and browserify-shim v 2.0.10

Could some body, please, tell me what I do wrong? And how to solve it?

mwmaleks avatar Mar 09 '14 07:03 mwmaleks

@mwmaleks use browserify-shim v3

deepak1556 avatar Mar 09 '14 08:03 deepak1556

Thank you! Now it works!

mwmaleks avatar Mar 09 '14 12:03 mwmaleks

I still encounter issues with browserify-shim, but only when using it with gulp-browserify.

My package.json

{
    "browserify": {
        "transform": [ "browserify-shim" ]
    },
    "browserify-shim": {
        "jquery": "global:jQuery"
    },
    "devDependencies": {
        "browserify": "^4.2.0",
        "browserify-shim": "^3.6.0",
        "gulp": "^3.8.5",
        "gulp-browserify": "^0.5.0"
    }
}

(I tried it with and without the browserify-part)

My gulpfile.js

var gulp       = require("gulp");
var browserify = require("gulp-browserify");

gulp.task("default",
    function ()
    {
        return gulp.src("in/*.js")
            .pipe(browserify({
                transform: ['browserify-shim']
            }))
            .pipe(gulp.dest("out/"));
    }
);

How I tried it

The CLI works just fine:

~/Desktop/gulp $ ./node_modules/.bin/browserify in/*.js
(function e(t,n,r){......

Gulp doesn't work however:

~/Desktop/gulp $ gulp
[19:47:20] Using gulpfile ~/Desktop/gulp/gulpfile.js
[19:47:20] Starting 'default'...

.../Desktop/gulp/node_modules/gulp-browserify/node_modules/browserify-shim/index.js:16
    throw new Error('browserify-shim needs to be passed a proper browserify in
          ^
Error: browserify-shim needs to be passed a proper browserify instance as the first argument.
 you passed:'.../Desktop/gulp/in/fake_7b97708d.js'

Exact versions:

~/Desktop/gulp $ npm ls --depth 0
@ ~/Desktop/gulp
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

@deepak1556 any idea?

apfelbox avatar Jul 03 '14 17:07 apfelbox

I ran into the same issue as @apfelbox today.

ghost avatar Jul 18 '14 17:07 ghost