-
Notifications
You must be signed in to change notification settings - Fork 368
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
Use JavaScript modules from Kotlin #10
base: master
Are you sure you want to change the base?
Conversation
Thanks a lot for creating this proposal for JavaScript modules support, I really appreciate such open process. What I like in the current proposal is a that this is a pragmatic solution that allows to choose how the generated code will load the modules (AMD, Common JS, UMD, etc.). Maybe the kind of module used could be just configured globally for a project, not sure if there is a real need to configure that for each module. But the Kotlin 1.1 is intended to support both Java 9 module system and ES6 module system. Why not trying to find a pragmatic solution (accordingly to Kotlin mindset) to define modules in Kotlin in a unified way that could be used to support Jigsaw and ES6 modules? I know there is differences between these module systems, but it seems to me that they share some common goals. Unlike Ceylon which created its own module system, Kotlin has wait enough for Jigsaw to be (almost) here so why not using that as an advantage to use the Kotlin way to handle Jigsaw modules to be able to generate also ES6 modules based on these common module metadatas? If Kotlin stdlib is modularized, that could help to avoid generating a 800 kbytes+ monolitic kotlin.js file, which is one of the main blocker for Kotlin usage for client side application IMO. Any thoughts about this common way of dealing with modules for both JVM and JavaScript platforms? |
Note it's only about consume JS modules in Kotlin. I.e. only about external declarations. |
We should investigate it separately. TBH I think the supporting Jigsaw will not significantly affect on JS.
We can split Advantages of the one "big" file:
Disadvantages:
Personally, I prefer to have one "big" file with analyzer friendly code. So for production You can minify your code + kotlin.js to get js file(s) with only necessary part. In addition I don't know how to split it in the best way. To tiny Anyway feel free to create issue or post where we can discuss about it separately. |
Accidentally some part of discussion is here |
The problem is not only consume but declare modules too. Some libraries like Aurelia needs this kind of structure and I had to create and define the modules by hand to let the systemjs load them, so aurelia can use them. I didn't think that kotlin should generate one JS for each file to be loaded as a module, because with that you will have to configure task builds using gulp or another to generate bundles. But after looking to the way kotlin resolve the project modules I think that, will a little change, you could use a way to continue working like today, but with some adapters to allow js module loaders to work. A quick example is change the About the runtime, well while I can agree with you about the big size, that will be good for apps and no for simple apps (page scripts). If you have to load 800kb to create a script of ten lines, then I'll prefer to write in pure JS or Typescript. And for some web apps that have multiple pages with little js inject into each, that is really a problem. To be honest, I think that, for JS only, most of the library should be defined in the kotlin-js-library with the most native functions as possible, or with polyfills to it. If you are a JVM programmer, you will like to use the things that you know at the web, but if you are a frontend programmer, comming from JS / TS, you will hate the fact that you will need to create almost all support for the language to be more "javascript friendly". |
… systems and without module systems
1c78663
to
af35c13
Compare
Ok so let's forget my idea for a common module support for Jigsaw and Javascript modules (maybe not doable) and let's discuss the scope of this proposal.
So the current scope of this proposal is only about consuming existing JS Modules, so declaring JS modules written in Kotlin is totally out of the scope and won't be supported? |
@sdeleuze: the ability to generate JS modules from kotlin code will in master soon |
FYI, I will create a dedicated thread about removing unused code for frontend application in https://discuss.kotlinlang.org/c/javascript. |
…ernative solution.
8935029
to
a52e37e
Compare
Should it be possible to put class A {
@JsModule("bbb") @native class B {
}
} |
Can @file:JsModule("foo")
package foo
@native fun bar()
@JsModule("baz") @native fun baz() |
What if a file is marked with |
Is |
|
Well, what is a problem? |
It looks inconsistent with, for example, |
Please clarify your thought.
For UMD we said:
|
Provide the way to add information about related JS module when write native declarations in Kotlin and use this information to generate dependencies.