fable-compiler / Fable

F# to JavaScript, TypeScript, Python, Rust and Dart Compiler
http://fable.io/
MIT License
2.92k stars 300 forks source link

Compile JS without bundling #800

Closed Neftedollar closed 7 years ago

Neftedollar commented 7 years ago

Fable 1.0 beta Subj

Pauan commented 7 years ago

Hmm, I wonder if rollup-loader can be used to reduce the amount of boilerplate.

alfonsogarciacaro commented 7 years ago

Fable 1.0 is delegating many of the functions implemented (with flaws) in previous versions of Fable like watching, resolving dependencies, etc. However, it shouldn't be difficult for the community to provide alternatives to fable-loader that communicate with Fable server independently. Could you give more details of your use case and what would you like the workflow to be, @Neftedollar? If you just want to hide the webpack config file, this would be as easy as creating a JS script that calls webpack under the hood with a default configuration.

Neftedollar commented 7 years ago

@alfonsogarciacaro I understand. I want to use fable with meteorjs. It has it's own filepreprocessing.(pack/unpack, deploying resolve dependencies etc. without webpack) Maybe I should go another way and use Fable-Compiler inside meteorjs workflow.

Or, fireloop has is it's own workflow too.

Neftedollar commented 7 years ago

https://guide.meteor.com/build-tool.html

jgrund commented 7 years ago

@Neftedollar Fwiw I did something like this with a Jest preprocessor: https://github.com/jgrund/jest-fable-preprocessor

As long as you can take the output from the fable server and push it into Babel, you should be able to get compilation without webpack working.

jgrund commented 7 years ago

@Pauan +1 from me for a rollup-loader. I'm working with node on the server-side so having rollup is more advantageous for me than webpack at the moment.

alfonsogarciacaro commented 7 years ago

@Neftedollar In this case, probably the best thing to do would be to create a custom build plugin for Meteor, but unfortunately the documentation seems to be very thing on this. I also had a look at the Typescript Meteor package and looks quite complicated.

It wouldn't be very difficult to create a standalone version of the fable-loader similar to Fable 0.7: a command to watch and/or compile F# files. The only thing I would like to avoid because it gave many headaches is putting the compiled Js files in a different directory. This is very tricky for files (both F# and JS) outside the project folder as it is not trivial to calculate the most efficient structure and resolve references from other files.

If you don't mind having the compiled JS files side by side with the F# files, I can try to implement something :+1:

BTW, @jgrund that's very advanced bit ofJS code, it wasn't easy to follow it ;)

Neftedollar commented 7 years ago

@alfonsogarciacaro I've found more useful text http://docs.meteor.com/api/packagejs.html#build-plugin-api

and this one for babel https://github.com/meteor/meteor/tree/devel/packages/ecmascript

alfonsogarciacaro commented 7 years ago

@Neftedollar Thanks, that's more complete info indeed. Will you give it a try at writing a Meteor plugin? @jgrund just created a Rollup plugin #808 you can use for reference. I can also quickly create a node script to translate F# to JS (ES2015) without Webpack but, as commented above, the JS files would be placed next to the F# files for simplification.

Neftedollar commented 7 years ago

@alfonsogarciacaro I think about it. There are some doubts about meteor's ecosystem with fable. Vanilla meteor is too barren without extensions/plugins.

as commented above, the JS files would be placed next to the F# files for simplification.

It'll be enough for proof of concept fable-meteor-compiler

alfonsogarciacaro commented 7 years ago

Maybe this could be a task for somebody in the @fable-compiler/code-maintenance group. Here's how I would do it:

If someone wants to volunteer, please send a WIP progress so we can continue discussion there :)

alfonsogarciacaro commented 7 years ago

I agree it's important for some scenarios to be able to compile JS without bundling as it was done in Fable 0.7. Someone from the @fable-compiler/code-maintenance would like to give it a try? I've outlined the necessary work above, but I can provide more guidance if needed.

MangelMaxime commented 7 years ago

@fable-compiler/code-maintenance I am going to work on this feature.

ncave commented 7 years ago

@alfonsogarciacaro Here is a WIP (#935) to kick off the discussion. It's still very raw, for now it just dumps the compiled .js directly in the outDir. Please share ideas on what the folder structure under outDir should look like.

mike-morr commented 7 years ago

@ncave @alfonsogarciacaro This looks pretty sweet! Putting my @fable-compiler/community team member hat on, this has been the most frequently requested feature from new people in Gitter!

ncave commented 7 years ago

@MangelMaxime Sorry about that, I did see your self-assignment, I just tried to contribute to the conversation to move it forward. Can we iterate / collaborate / share ideas to make it better?

MangelMaxime commented 7 years ago

@ncave No problem, I did have a working protytope. And was still trying to make my way around the solution.

I will try to take a look at your PR and sure we can collaborate / share idea based on it :) (Available, on the gitter or fsharp slack for easier discussion).

Alxandr commented 7 years ago

So I have non-bundles JS working in theory. I say in theory because I have other errors that makes me unable to test it (one of my files isn't properly compiling), but looking at the generated js files it seems it should be working. Script can be found here: https://gist.github.com/Alxandr/61e33157a3eba48436d53cc9194c269f

One cheviot: it only works if all you .fs files are in the same dir or bellow their respective .fsproj files. This could likely be fixed by simply loading all the projects first.

ncave commented 7 years ago

@Neftedollar You can try fable-splitter, see if it covers your use case. I'm sure it can be improved, the source is here.

Neftedollar commented 7 years ago

@ncave thanks! I'll try it on Saturday.

MangelMaxime commented 7 years ago

Should be close now ?

Alxandr commented 7 years ago

fable-builder also does this, but I'd argue that this is technically blocked / hacked until we can get list of files from fable server.

ncave commented 7 years ago

@Alxandr Traversing all the referenced paths in the Babel AST of each file gives you the relative .fs and .js file paths, see here.

Alxandr commented 7 years ago

@ncave yeah, I know. But it's sort of hacky not being able to ask fable for the files.