|
| 1 | +--- |
| 2 | +title: Start a new project |
| 3 | +layout: standard |
| 4 | +--- |
| 5 | + |
| 6 | +This guide you will show you how to create a Fable project from an F# project. |
| 7 | + |
| 8 | +<ul class="textual-steps"> |
| 9 | + |
| 10 | +<li> |
| 11 | + |
| 12 | +Create a new directory for your project and navigate to it. |
| 13 | + |
| 14 | +```bash |
| 15 | +mkdir my-fable-project |
| 16 | +cd my-fable-project |
| 17 | +``` |
| 18 | + |
| 19 | +</li> |
| 20 | + |
| 21 | +<li> |
| 22 | + |
| 23 | +Create a new F# project. |
| 24 | + |
| 25 | +```bash |
| 26 | +dotnet new console -lang F# |
| 27 | +``` |
| 28 | + |
| 29 | +You should now have 2 files: |
| 30 | + |
| 31 | +- `Program.fs`: the entry point of your app |
| 32 | +- `my-fable-project.fsproj`: the project file which lists your F# code files and libraries |
| 33 | + |
| 34 | +</li> |
| 35 | + |
| 36 | +<li> |
| 37 | + |
| 38 | +Install Fable tool so we can invoke it from the command line. |
| 39 | + |
| 40 | +```bash |
| 41 | +dotnet new tool-manifest |
| 42 | +dotnet tool install fable |
| 43 | +``` |
| 44 | + |
| 45 | +</li> |
| 46 | + |
| 47 | +<li> |
| 48 | + |
| 49 | +Add [Fable.Core](https://fable.io/packages/#/package/Fable.Core) to your project. |
| 50 | + |
| 51 | +```bash |
| 52 | +dotnet add package Fable.Core |
| 53 | +``` |
| 54 | + |
| 55 | +</li> |
| 56 | + |
| 57 | + |
| 58 | +<li> |
| 59 | + |
| 60 | +We can now call Fable to transpile our F# code to the desired target. |
| 61 | + |
| 62 | +```bash |
| 63 | +# If you want to transpile to JavaScript |
| 64 | +dotnet fable |
| 65 | + |
| 66 | +# If you want to transpile to TypeScript |
| 67 | +dotnet fable --lang typescript |
| 68 | + |
| 69 | +# If you want to transpile to Python |
| 70 | +dotnet fable --lang python |
| 71 | +``` |
| 72 | +:::info |
| 73 | +If you are switching between languages make sure to delete the `fable_modules` folder before invoking Fable again. |
| 74 | +::: |
| 75 | + |
| 76 | +You should now see a file `Program.fs.<ext>` where `<ext>` is the target language extension. For example, if you transpiled to JavaScript, you should see a `Program.fs.js` file. |
| 77 | + |
| 78 | +You can now use this file as you would use any other native file in your project. |
| 79 | + |
| 80 | +To go further look into the respective target documentation to have an example of how to use the generated file: |
| 81 | + |
| 82 | +- [JavaScript](/docs/getting-started/javascript.html) |
| 83 | +<!-- - [TypeScript](/docs/getting-started/typescript.html) |
| 84 | +- [Dart](/docs/getting-started/dart.html) |
| 85 | +- [Python](/docs/getting-started/python.html) |
| 86 | +- [Rust](/docs/getting-started/rust.html) |
| 87 | +- [PHP](/docs/getting-started/php.html) --> |
| 88 | + |
| 89 | +</li> |
| 90 | + |
| 91 | +</ul> |
0 commit comments