【问题标题】:Grunt-browserify+mapify+coffeescript = module not found with relative pathGrunt-browserify+mapify+coffeescript = 找不到相对路径的模块
【发布时间】:2014-06-26 17:25:27
【问题描述】:

我尝试让 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

非常感谢您的帮助。

【问题讨论】:

    标签: javascript node.js coffeescript gruntjs browserify


    【解决方案1】:

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

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

    必须是:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-13
      • 2017-01-05
      • 1970-01-01
      • 2013-07-16
      相关资源
      最近更新 更多