Use Jade as a Durandal View Engine?

Durandal looks like it supports custom viewers: http://durandaljs.com/documentation/View-Engine/

But it’s hard for me to understand what needs to be changed or added to use Jade templates as a Durandal viewer (on the client side, not on the server)

Should I completely rewrite the implementation of viewEngine.js in the Durandal source? ( https://github.com/BlueSpire/Durandal/blob/master/App/durandal/viewEngine.js )

Or is there a simpler approach, like adding jade as the requirejs loader? (e.g. https://github.com/rocketlabsdev/require-jade )

Any help would be appreciated.

Edit: I tried adding the above requirejs plugin to Durandal and setting it up via main.js:

requirejs.config({ paths: { ... 'jade': 'durandal/amd/jade' } }); ... var viewEngine = require('durandal/viewEngine'); viewEngine.viewExtension = ''; // Using .jade here results in requests for SomeView.jade.jade viewEngine.viewPlugin = 'jade'; 

But the view locator seems to have problems and doesn't know how to configure this setting. Note that I'm using the views (.html) and viewmodels (.js) convention, located side by side in the same directory, which works great

+4
source share
1 answer

viewEngine changing viewEngine , you can load and display .jade files. A monkey correcting the configuration of the requirejs path to the default viewEngine allows Durandal to load another viewer.

I hit something together here , the demo can be found here

Hope this helps you in the right direction.

+2
source

Source: https://habr.com/ru/post/1480018/


All Articles