UNPKG

2.19 kBMarkdownView Raw
1# Node API
2
3All 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```
14start(batfishConfig?: Object, projectDirectory?: string): EventEmitter
15```
16
17Start a development server.
18
19Returns 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```
28build(batfishConfig?: Object, projectDirectory?: string): EventEmitter
29```
30
31Build the static site.
32
33Returns 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```
43serveStatic(batfishConfig?: Object, projectDirectory?: string): EventEmitter
44```
45
46Serve the static site.
47
48Returns 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```
57writeBabelrc(batfishConfig?: Object, options?: {
58 outputDirectory: string,
59 target?: 'browser' | 'node'
60}): string
61```
62
63Write a `.babelrc` file based on Batfish's Babel defaults and your Batfish config file.
64This `.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).
65For 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