Grunt-browserify+mapify+coffeescript = module not found with relative path

隐身守侯 提交于 2020-01-04 01:57:07

问题


I try to get grunt-browserfy working with relative path for coffeescript but I always have an error message when I try to build my sources :

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

I have my file hierarchy presented like this :

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

I use grunt-browserify with the remapify plugin, coffeeify to transform my sources.

I also use the grunt-browserifyBower to build my libs, but this one works like a charm.

Here is an example of my 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'

An example of my 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"

And an example of my 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

Thanks a lot for any help.


回答1:


The problem come from the path to remapify :

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

Must be :

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


来源:https://stackoverflow.com/questions/23556690/grunt-browserifymapifycoffeescript-module-not-found-with-relative-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!