1 | # Node API
|
2 |
|
3 | All of the functions accept two optional arguments:
|
4 |
|
5 | - `batfishConfig`: See [`docs/configuration.md`](./configuration.md).
|
6 | - `projectDirectory`: Absolute path to the root directory of your projects.
|
7 | This is used to establish some default values for the configuration.
|
8 | For example, the default [`pagesDirectory`] value is `{projectDirectory}/src/pages`.
|
9 | Defaults to `process.cwd()`.
|
10 |
|
11 | ## start
|
12 |
|
13 | ```
|
14 | start(batfishConfig?: Object, projectDirectory?: string): EventEmitter
|
15 | ```
|
16 |
|
17 | Start a development server.
|
18 |
|
19 | Returns an EventEmitter that emits the following events.
|
20 |
|
21 | - `notification`: The listener is passed a string message.
|
22 | These are the messages logged by the CLI.
|
23 | - `error`: The listener is passed the error.
|
24 |
|
25 | ## build
|
26 |
|
27 | ```
|
28 | build(batfishConfig?: Object, projectDirectory?: string): EventEmitter
|
29 | ```
|
30 |
|
31 | Build the static site.
|
32 |
|
33 | Returns an EventEmitter that emits the following events.
|
34 |
|
35 | - `done`: Emitted when the build is complete.
|
36 | - `notification`: The listener is passed a string message.
|
37 | These are the messages logged by the CLI.
|
38 | - `error`: The listener is passed the error.
|
39 |
|
40 | ## serveStatic
|
41 |
|
42 | ```
|
43 | serveStatic(batfishConfig?: Object, projectDirectory?: string): EventEmitter
|
44 | ```
|
45 |
|
46 | Serve the static site.
|
47 |
|
48 | Returns an EventEmitter that emits the following events.
|
49 |
|
50 | - `notification`: The listener is passed a string message.
|
51 | These are the messages logged by the CLI.
|
52 | - `error`: The listener is passed the error.
|
53 |
|
54 | ## writeBabelrc
|
55 |
|
56 | ```
|
57 | writeBabelrc(batfishConfig?: Object, options?: {
|
58 | outputDirectory: string,
|
59 | target?: 'browser' | 'node'
|
60 | }): string
|
61 | ```
|
62 |
|
63 | Write a `.babelrc` file based on Batfish's Babel defaults and your Batfish config file.
|
64 | This `.babelrc` file can be used for other processes that run Babel and want to understand the source files that you write for Batfish (which end up going fed through Webpack).
|
65 | For example, you may want to generate a `.babelrc` file before running Jest tests against your client-side JS, so Jest can understand the same files that Batfish & Webpack do.
|
66 |
|
67 | `options.outputDirectory` defaults to the directory of your Batfish configuration.
|
68 |
|
69 | `options.target` defaults to `'node'`.
|
70 |
|
71 | [`pagesdirectory`]: ./configuration.md#pagesdirectory
|