Grunt-browserify + mapify + coffeescript =找不到相对路径的模块

时间:2014-05-09 04:36:36

标签: javascript node.js coffeescript gruntjs browserify

我试图让grunt-browserfy使用coffeescript的相对路径,但是当我尝试构建我的源时,我总是有一条错误消息:

>> Error: module "src/app/utils/includeMixin" not found from "/[ABSOLUTE-PATH-TO-MY-PROJECT]/project/src/app/app-audit.coffee"

我的文件层次结构如下所示:

project
 |- build
 |   |- libs.js
 |   |- audit.js
 |- src
     |- app
         |- app-audit.coffee
         |- utils
             |- includeMixin.coffee
     |- vendor
 |- node_modules
 |- gruntfile.coffee

我使用grunt-browserify和remapify插件,coffeeify来转换我的来源。

我也使用grunt-browserifyBower来构建我的库,但这个游戏就像魅力一样。

以下是我的gruntfile.coffee示例:

#Init grunt module
module.exports = (grunt) ->
    'use strict';

    remapify = require 'remapify'
    #Init Configuration
    grunt.initConfig
        browserify:
            dev:
                files:
                    "build/audit.js": ["src/app/app-audit.coffee"]
                options:
                    browserifyOptions:
                        extensions: ['.coffee']
                    bundleOptions:
                        debug: true
                    preBundleCB: (b) ->
                        b.plugin remapify, [{
                            src: 'src/**/*.*'
                            expose: 'src'
                            cwd: __dirname
                        }]
                    transform: ["coffeeify"]

        browserifyBower:
            app:
                options:
                    file: 'build/libs.js'

我的app-audit.coffee

的一个例子
# ## Description
# This file Manage the application's
# modules dependencies and instanciations

'use strict';

# ## Dependencies
# * Backbone Mixin includer
# (TODO : Link to the doc)
uIncludeMixin = require "src/app/utils/includeMixin"

我的includeMixin.coffee的一个例子

module.export = (mixins...) ->
  throw('include(mixins...) requires at least one mixin') unless mixins and mixins.length > 0

  for mixin in mixins
    for own key, value of mixin
      this::[key] = value

    included = mixin.included
    included.apply(this) if included

  this

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:5)

问题来自重新映射的路径:

            preBundleCB: (b) ->
                b.plugin remapify, [{
                    src: 'src/**/*.*'
                    expose: 'src'
                    cwd: __dirname
                }]

必须:

            preBundleCB: (b) ->
                b.plugin remapify, [{
                    src: './**/*.*'
                    expose: 'src'
                    cwd: __dirname + "/src"
                }]