UNPKG

4.28 kBMarkdownView Raw
1# Q & A
2
3## Table of contents
4
5- [Why not use a Webpack loader and allow import or require for CSS?](#why-not-use-a-webpack-loader-and-allow-import-or-require-for-css)
6- [Why not use a CSS-in-JS system?](#why-not-use-a-css-in-js-system)
7- [How can I use global constants in Markdown files?](#how-can-i-use-global-constants-in-markdown-files)
8- [How can I expose the Babel configuration that Batfish generates?](#how-can-i-expose-the-babel-configuration-that-batfish-generates)
9- [How can I pass my dependencies through Babel, if they need to be compiled?](#how-can-i-pass-my-dependencies-through-babel-if-they-need-to-be-compiled)
10- [What if I want to use React Router instead of Batfish's router?](#what-if-i-want-to-use-react-router-instead-of-batfishs-router)
11
12## Why not use a Webpack loader and allow `import` or `require` for CSS?
13
14We've found that getting CSS to load in the way we want it to (for both the development server and the static build) has been messy, buggy, and slow via existing Webpack patterns; so we decided to step outside of Webpack for this part of the build.
15However, you can add more Webpack loaders and plugins to accomplish this in your preferred way, if you'd like, using the [`webpackLoaders`] and [`webpackPlugins`] configuration options.
16
17## Why not use a CSS-in-JS system?
18
19You can use one if you'd like!
20Just include whatever tools and plugins you need.
21
22We've found that we can accomplish what we need to implement better optimizations by sticking with old fashioned CSS, so Batfish includes a system to optimize that use case.
23
24## How can I use global constants in Markdown files?
25
26In every Markdown file you can use the front matter array `prependJs` to specify lines of code to prepend to the compiled JS file.
27Here you can `import` constants and they will be available to interpolated JS expressions within the Markdown.
28
29```markdown
30---
31prependJs:
32 - "import constants from '../constants'"
33---
34
35Favorite color: {{ constants.FAVORITE_COLOR }}.
36```
37
38## How can I expose the Babel configuration that Batfish generates?
39
40Batfish generates a Babel configuration that combines its defaults with your [`babelPlugins`] and [`babelPresets`] options.
41If you want to test client-side JavaScript that relies on the transforms specified in this configuration, you can generate a `.babelrc` file that your test runner can read.
42
43```
44batfish write-babelrc
45```
46
47The above command will write a `.babelrc` file to the same directory as your Batfish configuration file.
48Then Jest or Ava or whatever it is can readthe `.babelrc` file and interpret your source code correctly.
49
50For more information about options for `write-babelrc`, run `batfish --help`.
51
52## How can I pass my dependencies through Babel, if they need to be compiled?
53
54Use the [`babelInclude`] option to point to the npm packages that need to be compiled.
55
56For example, if you want to use the library [p-queue](https://github.com/sindresorhus/p-queue) (which includes ES2015 syntax like `class` and arrow functions, and is *not* compiled to ES5 for publication), add the following to your configuration:
57
58```
59babelInclude: ['p-queue']
60```
61
62## What if I want to use React Router instead of Batfish's router?
63
64If you want to *nest* a React Router instance within Batfish pages, you can do that!
65This might be useful if, for example, you have detail pages that should not be statically rendered into tons of HTML pages, but instead generated in the client after an API call (e.g. `/dogs` lists all docs, then `/dogs/paul`, `/docs/dave`, `/dogs/*`, etc. are details for specific docs).
66Read about how to accomplish this in ["Routing within a page"].
67
68If you don't want to use Batfish's router *at all* (either because you have no routes or React Router handles them all), you should set `spa: true` in your configuration. Read more about the [`spa`] option.
69
70[`webpackloaders`]: ./configuration.md#webpackloaders
71
72[`webpackplugins`]: ./configuration.md#webpackplugins
73
74[`jsxtrememarkdownoptions`]: ./configuration.md#jsxtrememarkdownoptions
75
76[`babelplugins`]: ./configuration.md#babelplugins
77
78[`babelpresets`]: ./configuration.md#babelpresets
79
80[`babelinclude`]: ./configuration.md#babelinclude
81
82[`spa`]: ./configuration.md#spa
83
84["routing within a page"]: ./advanced-usage.md#routing-within-a-page