benbria / aliasify

Rewrite require calls in browserify modules.
MIT License
204 stars 26 forks source link

Does aliasify work with CoffeeScript files? #28

Open bennycode opened 9 years ago

bennycode commented 9 years ago

I am using grunt-browserify with these transforms declared in my package.json:

"browserify": {
  "transform": [
    "aliasify",
    "coffeeify",
    "browserify-shim"
  ]
}

When aliasify scans my CoffeeScript files then I get an error because it does not like CoffeScript symbols like ?=:

SyntaxError: Unexpected token (1:10) (while aliasify was processing config.coffee)

What can I do to make aliasify work with CoffeeScript?

I want to replace statements like:

CoreEvent = require '../../../core/coffee/event/CoreEvent.coffee'
jwalton commented 9 years ago

It does, although you need to have coffeeify ahead of aliasify in your transform stack.

bennycode commented 9 years ago

I tried that but then coffeify complains about not being able to resolve the mapping for require 'CoreEvent'.

jwalton commented 9 years ago

Do you have a small example project I can try this out on? We're using coffeeify and aliasify together (although we're running coffeeify@0.6.0, which is a bit old.)

maraujop commented 8 years ago

@bennyn I've made aliasify work with vueify having the exact same issue you had. This is how I've done it in my gulpfile:

    var aliasifyConfig = {
      "aliases": {
        "app": "./static/"
      },
      appliesTo: {
        "includeExtensions": ['.js', '.vue']
      }
    }

    return browserify({
      entries: [entry],
    })
      .transform(babelify)
      .transform(vueify)
      .transform(aliasify, aliasifyConfig)
      .bundle()

I read this section on browserify docs on how to make it follow different extensions, you would need to put .coffee in includeExtensions and I'm quite sure it would start working for you too.

Cheers, Miguel