Grunt-browserify + mapify + coffeescript =模块找不到相对路径 [英] Grunt-browserify+mapify+coffeescript = module not found with relative path
问题描述
我尝试使用coffeescript的相对路径工作,但我总是有一个错误消息: code>>>错误:/[ABSOLUTE-PATH-TO-MY-PROJECT]/project/src/app/app-audit.coffee中找不到模块src / app / utils / includeMixin
我的文件层次结构如下:
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来构建我的libs,但这一个像一个charm。 / p>
以下是我的gruntfile.coffee的示例:
#Init grunt模块
module.exports =(grunt) - >
'use strict';
remapify = require'remapify'
#Init配置
grunt.initConfig
browserify:
dev:
文件:
build / audit.js:[src / app / app-audit.coffee]
选项:
browserifyOptions:
extensions:['.coffee']
bundleOptions :
debug:true
preBundleCB:(b) - >
b.p.plugin remapify,[{
src:'src /**/*.*'
expose:'src'
cwd:__dirname
}]
transform:[coffeeify]
browserifyBower:
app:
options:
file:'build / libs.js'
我的app-audit.coffee的示例
###描述
#此文件管理应用程序的
#模块依赖项和实例
'use strict';
###依赖关系
#* Backbone混合包$
#(TODO:链接到文档)
uIncludeMixin = requiresrc / app / utils / includeMixin
我的includeMixin.coffee例子
module.export =(mixins ...) - >
throw('include(mixins ...)需要至少一个mixin'),除非mixins和mixins.length> 0
for mixin in mixins
for own key,value of mixin
this :: [key] = value
included = mixin.included
included.apply(this)如果包含
this
解决方案问题来自重新定义的路径:
preBundleCB:(b) - >
b.p.plugin remapify,[{
src:'src /**/*.*'
expose:'src'
cwd:__dirname
}]
必须是:
preBundleCB:(b) - >
b.p.papel remapify,[{
src:'./**/*.*'
expose:'src'
cwd:__dirname +/ src
}]
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.
解决方案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" }]
这篇关于Grunt-browserify + mapify + coffeescript =模块找不到相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!