问题
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