|
| 1 | +## Setup |
| 2 | + |
| 3 | +This build uses node version 18.15.0 and npm version. |
| 4 | +Install nvm and run the following commands: |
| 5 | + |
| 6 | +``` |
| 7 | +nvm install 18.15 |
| 8 | +nvm use 18 |
| 9 | +``` |
| 10 | + |
| 11 | +To build the library, run the following commands: |
| 12 | + |
| 13 | +``` |
| 14 | +npm install |
| 15 | +npm run build |
| 16 | +``` |
| 17 | + |
| 18 | +This will create the build in the dist folder. |
| 19 | + |
| 20 | +Open `examples/NeuralNetwork/index.html` in the browser to see the build running an example from the ml5 website. |
| 21 | + |
| 22 | +## Code Formatting |
| 23 | + |
| 24 | +To keep the coding style consistent, we will be using the Prettier formatter. |
| 25 | + |
| 26 | +### Visual Studio Code |
| 27 | + |
| 28 | +If you are using Visual Studio Code, you can install the Prettier extension by going to the **Extensions** tab and search for "Prettier". Click on **Prettier - Code formatter** and click **Install**. |
| 29 | + |
| 30 | +Go to **File > Preferences > Settings**, search for "default formatter" and make sure **Prettier - Code formatter** is selected for **Editor: Default Formatter**. |
| 31 | + |
| 32 | +To automatically format a document when saving it, search for "format on save" in the settings and make sure **Editor: Format On Save** is checked. Otherwise, you can use the VS Code keyboard shortcut to format an opened document, which is <kbd>shift</kbd> + <kbd>alt</kbd> + <kbd>f</kbd> for Windows or <kbd>shift</kbd> + <kbd>option</kbd> + <kbd>f</kbd> for Mac by default. |
| 33 | + |
| 34 | +### Command Line |
| 35 | + |
| 36 | +You can also format a document via the command line. To format all JavaScript documents in the repo, use: |
| 37 | + |
| 38 | +``` |
| 39 | +npm run format |
| 40 | +``` |
| 41 | + |
| 42 | +To format a specific document, use |
| 43 | + |
| 44 | +``` |
| 45 | +npx prettier --write path/to/file |
| 46 | +``` |
| 47 | + |
| 48 | +For more options with the command line, refer to the [Prettier Documentation](https://prettier.io/docs/en/cli.html) |
| 49 | + |
| 50 | +## Process |
| 51 | + |
| 52 | +_This section explains how this repository was creates and is for reference purposes only. The steps outlines in this section do not need to be followed by contributors._ |
| 53 | + |
| 54 | +I am building the library using Webpack, which was installed with: |
| 55 | + |
| 56 | +``` |
| 57 | +npm install --save-dev webpack webpack cli |
| 58 | +``` |
| 59 | + |
| 60 | +I also created package.json using `npm init` and set up a basic config file for a library build named `webpack.config.js`. I configured package.json so I could run webpack with `npm run build`. |
| 61 | + |
| 62 | +From the original ml5 library's `src` folder, I copied over all source files from the `NeuralNetwork` directory and necessary dependency files from `utils` directory. I also copied over `index.js` from the `src` folder and deleted everything unrelated to NeuralNetwork. I then installed `@tensorflow/[email protected]`, `@tensorflow/[email protected]`, and `[email protected]` with npm. |
| 63 | + |
| 64 | +At this point, the library can be built without error. I was only getting an error about exceeding recommended size limit. For the build, I am using the latest version of node, npm, and tfjs. I have not tested all the features of NeuralNetwork, but it appears to be working just fine. |
0 commit comments