Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

App with multiple views #127

Open
ravinggenius opened this issue Feb 25, 2018 · 2 comments
Open

App with multiple views #127

ravinggenius opened this issue Feb 25, 2018 · 2 comments

Comments

@ravinggenius
Copy link

I want to set the babel.only option without overwriting the remaining babel defaults. After looking through the source code, I found the only way to set babel.only was to copy the defaults and pass those through too.

server.engine('jsx', expressReact.createEngine({
	babel: {
		// glob includes all view directories in app, plus helper views like layout
		only: `${__dirname}/**/*.jsx`,
		presets: [
			'react',
			[
				'env',
				{
					targets: {
						node: 'current'
					}
				}
			]
		]
	}
}));

Would you be open to a pull request to add an extraPaths option? It would essentially change this line

assign({only: options.settings.views}, engineOptions.babel)

to

assign({only: [options.extraPaths, options.settings.views]}, engineOptions.babel)

This way I won't have to copy all the babel options just to set a custom/expanded babel.only.

@zpao
Copy link
Member

zpao commented Mar 3, 2018

IIRC this should already work if using multiple views (since #109). options.settings.views is coming from express and might be an array. Or at least that used to be true. I think rather than thread more options through we should figure out why options.settings.views doesn't already contain the path you want. Would you be able to help work that out? If we need to pass more paths through in options, so be it but would be nice to avoid if possible.

@ravinggenius
Copy link
Author

My files are grouped by domain instead of type (db access, routes, views for users are all together for instance). Each router sets a separate views directory (routes.set('views', path.join(__dirname, 'views'));), which is not know to the main app. The main app sets up the view engine:

server.engine('jsx', expressReact.createEngine({
	extraPaths: `${__dirname}/**/*.jsx`
}));

server.set('view engine', 'jsx');

I have to pass in the extra glob so layouts and shared components can be processed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants