browserify / bundle-collapser

convert bundle paths to IDs to save bytes in browserify bundles
Other
194 stars 21 forks source link

[Question] How to use it correctly in a gulp pipeline #19

Closed Kikobeats closed 8 years ago

Kikobeats commented 8 years ago

That's works perfectly:

gulp.task 'browserify', ->
  browserify()
    .require(src.vanilla, expose: 'linkifier')
    .bundle()
  .pipe source 'linkifier.js'
  .pipe uglify()
  .pipe header banner, pkg: pkg
  .pipe gulp.dest dist.folder

but when I add the plugin something happens:

gulp.task 'browserify', ->
  browserify()
    .require(src.vanilla, expose: 'linkifier')
    .plugin(collapse)
    .bundle()
  .pipe source 'linkifier.js'
  .pipe uglify()
  .pipe header banner, pkg: pkg
  .pipe gulp.dest dist.folder
❯ gulp browserify
[12:50:29] Requiring external module coffee-script/register
[12:50:31] Using gulpfile ~/Projects/linkifier/gulpfile.coffee
[12:50:31] Starting 'browserify'...
[12:50:31] 'browserify' errored after 16 ms
[12:50:31] SyntaxError: Unexpected token (1:8)
  at Parser.pp.raise (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:943:13)
  at Parser.pp.unexpected (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:1503:8)
  at Parser.pp.expect (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:1497:26)
  at Parser.pp.parseExprList (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:643:12)
  at Parser.pp.parseExprAtom (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:306:28)
  at Parser.pp.parseExprSubscripts (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:216:19)
  at Parser.pp.parseMaybeUnary (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:197:19)
  at Parser.pp.parseExprOps (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:151:19)
  at Parser.pp.parseMaybeConditional (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:133:19)
  at Parser.pp.parseMaybeAssign (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:110:19)
  at Parser.pp.parseExpression (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:86:19)
  at Parser.pp.parseStatement (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:1750:23)
  at Parser.pp.parseTopLevel (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:1666:21)
  at Parser.parse (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:1636:17)
  at parse (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/node_modules/acorn/dist/acorn.js:905:44)
  at module.exports (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/node_modules/browser-unpack/index.js:12:15)
  at module.exports (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/bundle-collapser/index.js:6:16)
  at Browserify.plugin (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/browserify/index.js:353:9)
  at Gulp.<anonymous> (/Users/josefranciscoverdugambin/Projects/linkifier/gulpfile.coffee:43:6)
  at module.exports (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/orchestrator/lib/runTask.js:34:7)
  at Gulp.Orchestrator._runTask (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/orchestrator/index.js:273:3)
  at Gulp.Orchestrator._runStep (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/orchestrator/index.js:214:10)
  at Gulp.Orchestrator.start (/Users/josefranciscoverdugambin/Projects/linkifier/node_modules/orchestrator/index.js:134:8)
  at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
  at nextTickCallbackWith0Args (node.js:420:9)
  at process._tickCallback (node.js:349:13)
  at Function.Module.runMain (module.js:443:11)
  at startup (node.js:139:18)
  at node.js:968:3

I suppose that I'm doing something but in the pipeline process, but what?

Kikobeats commented 8 years ago

Also this doesn't work for me

browserify(src.vanilla, {standalone: 'linkifier'})
    .plugin(require('bundle-collapser'))
    .bundle()
  .pipe source 'linkifier.js'
  .pipe uglify()
  .pipe header banner, pkg: pkg
  .pipe gulp.dest dist.folder
Kikobeats commented 8 years ago

fail: .plugin(require('bundle-collapser/plugin')), not bundle-collapser 😄

jonscottclark commented 8 years ago

Not a fail! By asking, you helped me (and probably many others).

Kikobeats commented 8 years ago

@jonscottclark perfect! 😄