dotnet-websharper / core

WebSharper - Full-stack, functional, reactive web apps and microservices in F# and C#
https://websharper.com
Apache License 2.0
593 stars 52 forks source link

Outputting JS from Library projects #1325

Closed granicz closed 10 months ago

granicz commented 1 year ago

The compiler/configuration setting "JsOutput" : "path" has been used to write out the "assembly-wide" JavaScript output into the file system (in addition to being stored in the DLL) up until WebSharper 6. However, this format is now changing with WebSharper 7 to take advantage of EcmaScript modules, as documented in #1318 .

This ticket is for the work involved to update JsOutput configurability to WebSharper 7.

The proposal is as follows:

  1. Output is written in a one-file-per-type (OFPT) format into files "assembly/typename.js", where assembly is the assembly name without the extension (such as WebSharper.UI), and typename is the full name of a type (module, class, or other type, such as WebSharper.UI.Var). Nested modules (F#) / classes (C#) produce output files for each non-empty module/class.

  2. If JsOutput is specified and refers to a folder (relative or absolute, ending with /), it's used as a prefix to the output files' location.

  3. If JsOutput is specified and refers to a file (ends with a file extension such as .js), an error is raised ("JavaScript file output is not implemented") - this might be revisited later on a subsequent ticket to enable "bundled" output.

  4. For any other value of JsOutput, do as follows: a. If it's any of "off"/"dll"/"none"/"" - don't output JS files. b. For everything else, yield a compiler warning ("Invalid value for JsOutput, assuming "none""), and assume it was "none".

  5. If JsOutput is not specified, no JS output files are written.

The JS output structure as defined in Part 0 above should be stored in the DLL as embedded resources, regardless of the choice of JsOutput.

And finally, to make it easier to access this feature, add "JsOutput" : "none" to wsconfig.json in the Library project templates (C# and F#) - and link the ticket for it here.

Jand42 commented 1 year ago

@granicz I don't like 3a. (If it's any of "off"/"dll"/"none"/"" - don't output JS files.) Why just not set/null? why magic aliases?

granicz commented 1 year ago

A concrete value and null would be a valid value set for an option setting (None or Some of x), but the current setting name (JsOutput) refers to the JS output without a "nothing/null" case ("and place that into the DLL and potentially in files too") and not the optionality of the file system location. We could go with what you suggest if the setting was called "JsOutputPath", but as it is, I'd prefer to go with the original 3a clause.

Jooseppi12 commented 10 months ago

After further discussion we ended up with just using null/not setting the JsOutput property in wsconfig to indicate that we don't want to write .js/.jsx files for the library project.