Brunch - Requiring modules outside of app directory

你。 提交于 2019-12-23 04:45:21

问题


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.

Currently, this works:


web/client/app/lib/router.coffee

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

web/client/app/lib/routesList.coffee

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

However, this doesn't:


web/client/app/lib/router.coffee

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

web/shared/routes/routesList.coffee

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

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?

Many thanks!

Update:

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...


回答1:


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

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


来源:https://stackoverflow.com/questions/26301406/brunch-requiring-modules-outside-of-app-directory

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