Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples for dojo/text or dojo/nls #10

Open
slimeygecko opened this issue Nov 8, 2016 · 6 comments
Open

Examples for dojo/text or dojo/nls #10

slimeygecko opened this issue Nov 8, 2016 · 6 comments

Comments

@slimeygecko
Copy link

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?

@anatoliyarkhipov
Copy link

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.

@slimeygecko
Copy link
Author

slimeygecko commented Nov 9, 2016

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...

@fmatuszewski
Copy link

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

@fmatuszewski
Copy link

should I more 'dojo/text!./templates/databar.html'
Inside and use require(['dojo/text!./templates/databar.html',function()])

@slimeygecko
Copy link
Author

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.

@slimeygecko
Copy link
Author

slimeygecko commented Nov 23, 2016

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.

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

No branches or pull requests

3 participants