早午餐 - 需要app目录之外的模块 [英] Brunch - Requiring modules outside of app directory

查看:102
本文介绍了早午餐 - 需要app目录之外的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处这里,但它们是关于使用NPM模块,而我的问题涉及同构内部代码,其中我想在brunch / backbone和node / express之间共享路由。但是,如果这是一个骗局,那么请提前道歉!

There have been answers here and here, but they're about using NPM modules whilst my problem involves isomorphic internal code, where I want to share routes between brunch/backbone and node/express. But, if this is a dupe, then apologies in advance!

以下代码高度简化/伪,顺便说一句。

The following code is highly simplified/pseudo, btw.

目前,这有效:

Routes = require 'lib/routesList'
module.exports = class Router extends Backbone.Router
  routes: Routes.get()



web / client / app / lib / routesList.coffee



web/client/app/lib/routesList.coffee

module.exports = do () ->
  get: () ->
    return {'': 'dashboard', 'settings': 'settings'}






然而,这不是:


However, this doesn't:

Routes = require '../../shared/routes/routesList'
module.exports = class Router extends Backbone.Router
  routes: Routes.get()



web /shared/routes/routesList.coffee



web/shared/routes/routesList.coffee

module.exports = do () ->
  get: () ->
    return {'': 'dashboard', 'settings': 'settings'}






我不是试图让节点模块与Brunch一起工作 - 我知道不支持 - 但是,只要将这些常见的js模块连接到app.js就可以了。它们都不在app目录中?


I'm not trying to get node modules to work with Brunch- I know that's not supported- but is it at all possible to just concatenate these common js modules together into app.js when they don't all reside within the app directory?

非常感谢!

我最终在 web / client / app / shared - > web / shared之间创建了一个符号链接它现在有效,但我不知道是否有更清洁的方式......

I ended up creating a symbolic link between web/client/app/shared -> web/shared and it now works, but I don't know if there's a cleaner way...

推荐答案

../../ shared 添加到早午餐配置中的观察路径

Add ../../shared to the watched paths in your brunch config

paths:
  watched: ['app', 'vendor', '../../shared']

这篇关于早午餐 - 需要app目录之外的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆