ui.js icon indicating copy to clipboard operation
ui.js copied to clipboard

Dev module tree shaking

Open devingfx opened this issue 3 years ago • 7 comments

Hi,

I had split classes to separated files and added a rollup dev dependancy to merge it again and produce the exact same file (ok maybe 2 extra blank lines and UITab being moved before UITabbedPanel who depends on it).

I added the build results to avoid forcing users to build themself and let them use the ui.js directly as before...

The build contains the same ui.js as original and a namespaced one ui.ns.js to be used without modules using a global script tag (see README).

Hope this can help to get more contributions...

devingfx avatar Sep 29 '21 17:09 devingfx

Everything looks good but I would remove the ui.ns.js build and related code. This lib was already modules-only.

mrdoob avatar Sep 29 '21 19:09 mrdoob

Why not let the choice to the user for modules or not? It's already there... ( please note I'm in favor of modules anyway, but the need of a webserver may bother some cases )

Another thing is that src/namespace.js (that produce ui.ns.js) is also a way to get bindings without the "UI" prefix that can be a bit redundant when all classes are imported with a

import * as UI from './src/index.js'

new UI.UIText()

against

import * as UI from './src/namespace.js'

new UI.Text()

(please note that function (class) names are always 'UI' prefixed aka UI.Text.name == "UIText" )

... btw, I'll do how you want, but I wanted to expose arguments why this version exists ;)

devingfx avatar Sep 30 '21 08:09 devingfx

Another question I had :

Do you want rollup to produce the file in src/ui.js as before? I did create a build folder as usual but it easy to change...

devingfx avatar Sep 30 '21 09:09 devingfx

Why not let the choice to the user for modules or not?

Because the more "choices" the more things to maintain in the future.

mrdoob avatar Oct 04 '21 22:10 mrdoob

Do you want rollup to produce the file in src/ui.js as before? I did create a build folder as usual but it easy to change...

No need. The simpler the PR the better 🙂

mrdoob avatar Oct 04 '21 22:10 mrdoob

import * as UI from './src/index.js'

new UI.UIText()

That's not how the library is supposed to be used though.

It's supposed to be used like this:

import { UIText } from './src/index.js'

new UIText()

mrdoob avatar Oct 04 '21 22:10 mrdoob

HI!

I just did the changes said above... I'm not sure about the README change because it was show the "choices" for importing, but there is no choices anymore... You may not merge this last commit...

I'm not sure what to do about the old file in src/ui.js, you guys from three/editor may still need it right know, dunno :) So I kept it !

devingfx avatar Oct 07 '21 14:10 devingfx