Steven
Steven

Reputation: 1596

Gulp + Browserify: CoffeeScript not loading when loading files from node_modules

After setting up the folder structure for my Gulp project, I was wondering how to do paths in browserify, and found this page: https://github.com/substack/browserify-handbook#organizing-modules. It recommends putting common application parts in a subfolder of node_modules. This appears to be working, it's getting the files, but it's not applying my coffeeify transform, so it's throwing errors because it's trying to interpret them as JS. Any ideas how to fix this? This is my browserify config:

browserify: {
  // Enable source maps
  debug: true,
  // Additional file extentions to make optional
  extensions: ['.coffee', '.hbs'],
  // A separate bundle will be generated for each
  // bundle config in the list below
  bundleConfigs: [{
    entries: src + '/javascript/app.coffee',
    dest: dest,
    outputName: 'app.js'
  }, {
    entries: src + '/javascript/head.coffee',
    dest: dest,
    outputName: 'head.js'
  }]
}

and these are the relevant bits form my package.json.

"browserify": {
  "transform": [
    "coffeeify",
    "hbsfy"
  ]
}

Upvotes: 2

Views: 233

Answers (1)

pgreen2
pgreen2

Reputation: 3651

Transfroms aren't applied to files in node_modules unless they are marked as being global: https://github.com/substack/node-browserify#btransformtr-opts. If you choose to make it global, be warned, the documentation suggests against it:

Use global transforms cautiously and sparingly, since most of the time an ordinary transform will suffice.

You won't be able to specify the tranform in package.json:

You can also not configure global transforms in a package.json like you can with ordinary transforms.

The two options are programmatically, by passing {global: true} as options or at the command line with the -g option:

browserify -g coffeeify main.coffee > bundle.js

Upvotes: 1

Related Questions