dojo-webpack-loader
dojo-webpack-loader copied to clipboard
Examples for dojo/text or dojo/nls
I seem to be having trouble with dojo-webpack-loader when using dojo/text. I've looked through the example js files and can't find one that directly uses dojo/text or dojo/nls..
It appears as if webpack uses exclamation marks for loaders, as you alluded to in the readme. I've been able to sort of get around this if I use an alias, but I was hopeful that the dojo-webpack-loader would be able to get around these issues with webpack.
Thoughts?
We also had some problems with dojo/text
(I don't remember what problems exactly) and to fix them we installed the text-loader
package and wrote an alias for dojo/text
. The webpack config section with the alias looks like this:
resolveLoader: {
modulesDirectories: [
path.resolve(__dirname, './node_modules/'),
path.resolve(__dirname, './bower_components/'),
],
alias: {
'dojo/text': 'text',
},
},
After this every module that tries to use dojo/text!
actually will use the text-loader
. And it works fine.
That seems to work, thanks! Also, I guess text-loader
is the same as or does the same as raw-loader
. Now I just have to figure out how to load multiple resources at once for the application I've been working on here at work..
We have a module that uses the dojo loader lifecycle to load multiple resources at once.. see below:
require(['nlsModule!resource1,resource2,resource3'], function(resources) { \\do stuff });
and the module definition:
define(['dojo/_base/array', 'dojo/_base/lang', 'wtl/classes/locale'], function (array, lang, locale) {
return {
load: function (id, require, load) {
var names = id.split(','),
results = {},
cnt = 0;
array.forEach(names, function (name) {;
require(['dojo/text!/api/resource/' + locale.getLocale() + '/' + name], function (text) {
lang.mixin(results, JSON.parse(text));
if (++cnt === names.length) {//we're all done!
load(results);
}
});
});
}
};
})
I've been working on a solution using commonjs (synchronous) but need to work out all the details still...
What if I define module like this: define(['browser/extensions/ewniosek/DataSurfaces', 'browser/utils/Resources', 'dijit/Tooltip', 'dojo/query', 'dojo/html', 'dojo/on', 'dojo/dom-construct', 'dojo/text!./templates/databar.html' ], function (DataSurfaces, Resources, Tooltip, query, html, on, domConstruct, content) {
Can I use the same solution. I configured alias like this resolve: { alias: { "dojo": path.resolve(__dirname, './dojo/dojo'), "dstore": path.resolve(__dirname, './dojo/dstore'), "dijit": path.resolve(__dirname, './dojo/dijit'), "dgrid": path.resolve(__dirname, './dojo/dgrid'), "cbtree": path.resolve(__dirname, './dojo/cbtree'), "dojox": path.resolve(__dirname, './dojo/dojox'), "browser": path.resolve(__dirname, './dojo/browser'), 'dojo/text': 'text',
}
},
and still have the same issue.
WARNING in ./dojo/browser/layout/templates/mainMenu.html
Module parse failed: c:\Users\matuszef\Documents\Projects\dojo-webpack-loader-examples\dojo\browser\layout\templates\mainMenu.html Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (1:0)
at Parser.pp$4.raise (c:\Users\matuszef\Documents\Projects\dojo-webpack-loader-examples\node_modules\acorn\dist\acorn.js:2221:15)
at Parser.pp.unexpected (c:\Users\matuszef\Documents\Projects\dojo-webpack-loader-examples\node_modules\acorn\dist\acorn.js:603:10)
at Parser.pp$3.parseExprAtom (c:\Users\matuszef\Documents\Projects\dojo-webpack-loader-examples\node_modules\acorn\dist\acorn.js:1822:12)
at Pars
should I more 'dojo/text!./templates/databar.html' Inside and use require(['dojo/text!./templates/databar.html',function()])
yea, I noticed that too. Dojo/text does more than just load raw strings. It also looks like it parses xml and potentially other formats. When you alias to raw-loader, dojo/text doesn't parse the data. I'll have to look at that tomorrow when I have a little time, maybe I can help sort this out.
Webpack uses the '!' symbol in require statements as a way to use loaders in-line. I had to use the normalModuleReplacementPlugin in my webpack config to get around some of the oddities of dojo.
I've put up my working demo here dojo-webpack-loader-additional-examples. I also put together resx-webpack-loader that transforms resx files into javascript objects.