我尝试让 grunt-browserify 使用 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
非常感谢您的帮助。