contextRequire mapped to require works for relative.

master
Tomasz Półgrabia 2021-12-19 20:31:34 +01:00
parent 4407cd934d
commit 3d2d3915ef
4 changed files with 47 additions and 7 deletions

View File

@ -0,0 +1 @@
//

View File

@ -0,0 +1,16 @@
define([
"dojo/parser",
"dijit/_TemplatedMixin",
"dijit/_WidgetBase",
"dojo/_base/declare"
], function(parser, _TemplatedMixin, _WidgetBase, declare, template) {
var widget = declare("app/widgets/ChildWidget2", [_WidgetBase, _TemplatedMixin], {
templateString: "<div>"
+ "ChildWidget!!!"
+ "</div>"
});
// parser.parse();
return widget;
});

View File

@ -1,14 +1,19 @@
define([ define([
"require",
"dijit/_TemplatedMixin", "dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dijit/_AttachMixin", "dijit/_AttachMixin",
"dijit/_WidgetBase", "dijit/_WidgetBase",
"dojo/_base/declare" "dojo/_base/declare",
], function(_TemplatedMixin, _AttachMixin, _WidgetBase, declare, template) { "dijit/form/TextBox",
return declare("app/widgets/MainWidget", [_WidgetBase, _AttachMixin, _TemplatedMixin], { "./ChildWidget2"
], function(require, _TemplatedMixin, _WidgetsInTemplateMixin, _AttachMixin, _WidgetBase, declare) {
return declare("app/widgets/MainWidget", [_WidgetBase, _AttachMixin, _TemplatedMixin, _WidgetsInTemplateMixin], {
contextRequire: require,
templateString: "<div>" templateString: "<div>"
// + "Hello World!!! <input data-dojo-type=\"dijit/form/TextBox\" />" // + "Hello World!!! <input data-dojo-type=\"dijit/form/TextBox\" />"
// this works as it's dijit // this works as it's dijit
+ "<div data-dojo-type=\"./ChildWidget\"></div>" + "<div data-dojo-type=\"./ChildWidget2\"></div>"
// this doesn't work as it's trying to fetch ./node_modules/dojo/ChildWidget which seems to be // this doesn't work as it's trying to fetch ./node_modules/dojo/ChildWidget which seems to be
// relative to dojo/parser dojo/parser // relative to dojo/parser dojo/parser
+ "</div>" + "</div>"

View File

@ -7,15 +7,21 @@
<!--dojoConfig--> <!--dojoConfig-->
<script> <script>
// var arguments = []; // rhino fails if it's not set up
var dojoConfig = { var dojoConfig = {
has: {
// "host-rhino": true, // why some rhino platform is a key to override baseUrl?
},
parseOnLoad: true, parseOnLoad: true,
isDebug: true,
async: true, async: true,
cacheBust: true, // Get "fresh" resources, cacheBust: false, // Get "fresh" resources,
baseUrl: "/app", baseUrl: "/app",
packages: [ packages: [
{name: "dojo", location: "/node_modules/dojo"}, {name: "dojo", location: "/node_modules/dojo"},
{name: "dojox", location: "/node_modules/dojox"}, {name: "dojox", location: "/node_modules/dojox"},
{name: "dijit", location: "/node_modules/dijit"} {name: "dijit", location: "/node_modules/dijit"},
{name: "app", location: "./"}
] ]
}; };
</script> </script>
@ -30,7 +36,19 @@
"app/widgets/MainWidget.js", "app/widgets/MainWidget.js",
"dojo/domReady!" "dojo/domReady!"
], function (dom, parser, MainWidget) { ], function (dom, parser, MainWidget) {
parser.parse(); // parseOnLoad: true doesn't run this. Why??? // parser.parse();
// parseOnLoad: true doesn't run this. Why???
// parser.parse({
// scope: "app"
// });
/**
parser.parse({
"contextRequire": require,
"_dojoParserCtorMap": {
"./ContentPane": require('dijit/layout/ContentPane'),
}
});
**/
var greeting = dom.byId('root'); var greeting = dom.byId('root');
var widget = new MainWidget(); var widget = new MainWidget();
widget.placeAt(greeting); widget.placeAt(greeting);