|
1 | 1 | # ml5-neuralnetwork-test-build
|
| 2 | + |
2 | 3 | This is a test repo to see what it would take to build only the NeuralNetwork feature of the ml5 library.
|
3 | 4 |
|
4 | 5 | ## Setup
|
| 6 | + |
5 | 7 | This build uses node version 18.15.0 and npm version.
|
6 | 8 | Install nvm and run the following commands:
|
| 9 | + |
7 | 10 | ```
|
8 | 11 | nvm install 18.15
|
9 | 12 | nvm use 18
|
10 | 13 | ```
|
11 | 14 |
|
12 |
| - |
13 | 15 | To build the library, run the following commands:
|
| 16 | + |
14 | 17 | ```
|
15 | 18 | npm install
|
16 | 19 | npm run build
|
17 | 20 | ```
|
18 |
| -This will create the build in the dist folder. |
19 | 21 |
|
| 22 | +This will create the build in the dist folder. |
20 | 23 |
|
21 | 24 | Open `examples/NeuralNetwork/index.html` in the browser to see the build running an example from the ml5 website.
|
22 | 25 |
|
23 | 26 | ## Code Formatting
|
24 |
| -To keep the coding style consistent, we will be using the prettier formatter. |
25 | 27 |
|
| 28 | +To keep the coding style consistent, we will be using the Prettier formatter. |
| 29 | + |
| 30 | +### Visual Studio Code |
| 31 | + |
| 32 | +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**. |
| 33 | + |
| 34 | +Go to **File > Preferences > Settings**, search for "default formatter" and make sure **Prettier - Code formatter** is selected for **Editor: Default Formatter**. |
| 35 | + |
| 36 | +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. |
| 37 | + |
| 38 | +### Command Line |
26 | 39 |
|
| 40 | +You can also format a document via the command line. To format all JavaScript documents in the repo, use: |
| 41 | + |
| 42 | +``` |
| 43 | +npm run format |
| 44 | +``` |
| 45 | + |
| 46 | +To format a specific document, use |
| 47 | + |
| 48 | +``` |
| 49 | +npx prettier --write path/to/file |
| 50 | +``` |
| 51 | + |
| 52 | +For more options with the command line, refer to the [Prettier Documentation](https://prettier.io/docs/en/cli.html) |
27 | 53 |
|
28 | 54 | ## Process
|
29 |
| -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. |
| 55 | + |
| 56 | +_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._ |
30 | 57 |
|
31 | 58 | I am building the library using Webpack, which was installed with:
|
| 59 | + |
32 | 60 | ```
|
33 | 61 | npm install --save-dev webpack webpack cli
|
34 | 62 | ```
|
35 | 63 |
|
36 | 64 | 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`.
|
37 | 65 |
|
38 |
| - |
39 | 66 | 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.
|
40 | 67 |
|
41 |
| - |
42 | 68 | 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