Hi, "src/pkg/uki.js" "global" is not defined

61 views
Skip to first unread message

Meai

unread,
Apr 16, 2011, 3:05:37 PM4/16/11
to ukijs
I understand that the "global" variable is somehow defined in
"static_require.js" right? How do I get this to work so I can start
developing on the client? I don't need node.js just to run code right?

Volodya Kolesnikov

unread,
Apr 16, 2011, 10:38:15 PM4/16/11
to uk...@googlegroups.com
0.4 is in development now. So there's no packed version. To run you
need node.js. I'll create one as soon as it stabilize enough.

Meai

unread,
Apr 17, 2011, 5:03:29 AM4/17/11
to ukijs
It's okay, I have node and I'm able to run the examples. I just don't
understand why I need it and how to run something other than examples.

I don't want to develop on a packed version anyway, because it's too
hard to understand a library when it is packed into a single, huge
file.
I understand the express.js part, it redirects to the examples
folders.
It appears that we parse all the requireText() and requireCss() calls
and convert them to some code.

Can you explain a little what the nodejs code does and why we do it?
I'm sure it would be possible to have a library without having to
parse raw css and javascript, why not just define global methods for
requireText() etc, instead of parsing?

Vladimir Kolesnikov

unread,
Apr 17, 2011, 5:23:36 AM4/17/11
to uki google group
node.js does static packaging the app in a single file on the fly. The
main part is require function from CommonJS spec:
http://www.commonjs.org/specs/modules/1.0/ It will require exported
members from the module. Check the spec for more info. CommonJS spec also
contains global, module and exports special variables. One of the
intersting points of using require on the client is that you can share
code between server and client without extra effort. You can just require
the same modules both in node code and on the client. Plus as of now you
can distribute uki modules as usual node modules with npm.

There are also 2 extra methods specifically for uki: requireCss and
requireText.
- requireText will directly embed content of a file into the code as a
string. It works with templates. Instead of loading template from a server
with a separate request it's often much easier to embed the template
directly into the JS file. It will generally be faster to load. So
requireText does just that. When you do
Mustache.to_html(requireText('my.html'), {}) it will be expanded into
Mustache.to_html('<code>{{{value}}}</code>', {});
- requireCss will embed css code into js. It will also minimize css
(remove spaces) and embed images using data:uri. You can then access
imported css all as one chunk using __requiredCss variable.

Both of this methods allow to put all resources related to a single view
in one place. It also simplifies deployment (single js file instead of
several folders) and loading speeds.

All of the code responsible for that is in tools/static_require.js
Hope that helps

Meai

unread,
Apr 17, 2011, 6:47:30 AM4/17/11
to ukijs
> node.js does static packaging the app in a single file on the fly.

Where do you see that? When I define a new nodejs module, it doesn't
produce a single file. I can see both files in the eclipse debugger,
and I can step through the code.

The same doesn't seem to be true for ukijs:
The ukijs code shows up as a single huge line in the debugger.
And this huge line is a combination of all require'd modules, with
auto generated names like "require_modules[15]". How do you debug
something like that? How do you know what "require_modules[15]" means?
I don' understand how you can work like this, it's maybe nice **for
production** if everything is generated into a single file, but for
debugging?...



On Apr 17, 11:23 am, Vladimir Kolesnikov <vol...@gmail.com> wrote:
> node.js does static packaging the app in a single file on the fly. The
> main part is require function from CommonJS spec:http://www.commonjs.org/specs/modules/1.0/It will require exported
> members from the module. Check the spec for more info. CommonJS spec also
> contains global, module and exports special variables. One of the
> intersting points of using require on the client is that you can share
> code between server and client without extra effort. You can just require
> the same modules both in node code and on the client. Plus as of now you
> can distribute uki modules as usual node modules with npm.
>
> There are also 2 extra methods specifically for uki: requireCss and
> requireText.
> - requireText will directly embed content of a file into the code as a
> string. It works with templates. Instead of loading template from a server
> with a separate request it's often much easier to embed the template
> directly into the JS file. It will generally be faster to load. So
> requireText does just that. When you do
> Mustache.to_html(requireText('my.html'), {}) it will be expanded into
> Mustache.to_html('<code>{{{value}}}</code>', {});
> - requireCss will embed css code into js. It will also minimize css
> (remove spaces) and embed images using data:uri. You can then access
> imported css all as one chunk using __requiredCss variable.
>
> Both of this methods allow to put all resources related to a single view
> in one place. It also simplifies deployment (single js file instead of
> several folders) and loading speeds.
>
> All of the code responsible for that is in tools/static_require.js
> Hope that helps
>

Vladimir Kolesnikov

unread,
Apr 17, 2011, 4:50:32 PM4/17/11
to uki google group
Compression to one line is caused by recent update in uglify-js. I just
fixed it yesterday. Please pull the new version from github or npm install
ukijs. Once updated it should produce a single multy-line file with all
the original files merged together.

node.js itself does not modify your client files. static_require does.
Once you load something as src/uki.js node.js server will process this
file using static_require handler. static_require will process require(),
requireText() and requireCss() calls. You can add ?squeeze=1 to the path
(src/uki.js?squeeze=1) to get a single line, compressed production version.

Johan Rydberg

unread,
Apr 21, 2011, 1:08:43 PM4/21/11
to uk...@googlegroups.com
I've hacked up a small "off-line packer" in python:

  https://gist.github.com/935004

It's pretty much a re-write of Vladimir's stuff in static_require.js.

Run like this:

python pack-ukijs.py -I src examples/core-examples/dataList/dataList > dataList.js
Reply all
Reply to author
Forward
0 new messages