You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`doctype` - string which will be prepended to output html, default value is `"<!DOCTYPE html>\n"`
170
-
*`replace` - function which will take output html (without doctype) and it should return new html
175
+
*`replace` - function which will take output html (without doctype), and it should return new html
171
176
*`templatePath` - path to wrapper of compiled jsx, default value is `express-engine-jsx/template.jsx`. Undefined variable `BODY` will be replaced with your compiled jsx code.
172
177
*`parserOptions` - options for [babel.parser](https://babeljs.io/docs/en/babel-parser#options)
178
+
*`templateOptions` - options for [babel.template](https://babeljs.io/docs/en/babel-template#options)
This is a function which you can use as regular `require` but this one can run jsx files. It checks if path is jsx file and if it is then `requireJSX` will [convert](#convert) this file to js code and then run it.
181
187
182
-
Every compiled jsx file will be cached to `requireJSX.cache` object where key will be path to jsx file and value will be [vm.Script](https://nodejs.org/api/vm.html#vm_class_vm_script).
188
+
It also takes optional second parameter - `currentWorkingDir` which should be an absolute path to file directory which calls `require` in case when main path is relative.
189
+
190
+
Every compiled jsx file will be cached to `requireJSX.cache` object where key will be path to jsx file and value will be value of `module.exports` inside jsx file, usually react component.
183
191
You can delete any key in this cache, requireJSX will recompile jsx file on next call.
It is a function which can convert jsx view files to [vm.Script](https://nodejs.org/api/vm.html#vm_class_vm_script).
192
-
```js
193
-
constscript=convert('/path/to/view.jsx');
194
-
195
-
constcontext= {
196
-
module: {
197
-
exports: {}
198
-
},
199
-
__dirname:script.dirname,
200
-
require: requireJSX,
201
-
};
199
+
It is a function which can convert jsx template code to js code.
200
+
201
+
Arguments:
202
+
203
+
*`code` - string of jsx code
204
+
*`options`
205
+
*`parserOptions` - options for [babel.parser](https://babeljs.io/docs/en/babel-parser#options)
206
+
*`template` - string of jsx code wrapper
207
+
*`templatePath` - string, path to jsx code wrapper
208
+
*`templateOptions` - options for [babel.template](https://babeljs.io/docs/en/babel-template#options)
209
+
210
+
It also has `convert.cache` object for compiled templates where keys are `templatePath` and values are functions created by [babel.template](https://babeljs.io/docs/en/babel-template)
0 commit comments