flecks/packages/core/build/dox/concepts/build.md

99 lines
3.4 KiB
Markdown
Raw Normal View History

2022-02-25 04:58:08 -06:00
# Build directory ⚡️
The `build` directory is where build-time configuration is specified.
The prime example of this for Flecks is `flecks.yml`, but it extends to other more general
configuration such as `.eslintrc.js`, `babel.config.js`, etc.
2022-03-09 14:48:19 -06:00
For a list of all build configuration, see the
[build configuration page](https://github.com/cha0s/flecks/blob/gh-pages/build-configs.md)
2022-02-25 04:58:08 -06:00
## `flecks.yml` ⛏️
`flecks.yml` specifies the flecks that compose your project.
Using `@flecks/create-fleck` creates the following `flecks.yml`:
```yml
'@flecks/core': {}
'@flecks/fleck': {}
```
This means that by default a new fleck will pull in the `@flecks/core` fleck, and the
`@flecks/fleck` fleck, both with default configuration.
### Overriding configuration 💪
`@flecks/core`'s configuration has an `id` key. Starting from the example above, overriding the
ID to, say, `'example'`, would look like this:
```yml
'@flecks/core':
id: 'example'
'@flecks/fleck': {}
```
2022-03-09 14:52:32 -06:00
See [the configuration page](https://github.com/cha0s/flecks/blob/gh-pages/config.md) for a list of
all configuration.
2022-03-09 14:48:19 -06:00
2022-02-25 04:58:08 -06:00
### Aliasing 🕵️‍♂️
Flecks may be aliased to alternative paths.
Say you have an application structured as a monorepo with a `packages` directory. If you have a
subpackage named `@my-monorepo/foo`, you could alias your fleck, like so:
```yml
'@flecks/core': {}
'@flecks/server': {}
'@my-monorepo/foo:./packages/foo/src': {}
```
Within your application, the fleck will be referred to as `@my-monorepo/foo` even though
`./packages/foo/src` is where the package is actually located.
This way you can use package structure without having to worry about actually publishing them to
npm (or running verdaccio, for instance).
## On-the-fly compilation(!) 🤯
If your flecks are aliased (as above) or symlinked (e.g. `yarn link`), they will be treated
specially and will be compiled on-the-fly. The flecks are searched for a local `babel.config.js`,
which is used to compile the code if present.
This means you can e.g. develop your `packages` in a monorepo with full HMR support, on both the
server and the client, each with their own babel configuration!
Have fun!
## Resolution order 🤔
2022-03-09 07:25:58 -06:00
The flecks server provides an interface (`flecks.buildConfig()`) for gathering configuration files
2022-02-25 04:58:08 -06:00
from the `build` directory. The resolution order is determined by a few variables:
2023-11-30 21:41:42 -06:00
- `filename` specifies the name of the configuration file, e.g. `server.webpack.config.js`.
2022-02-25 04:58:08 -06:00
2023-11-30 21:41:42 -06:00
- `general` specifies a general variation of the given configuration. The general form of `server.webpack.config.js` is `webpack.config.js`.
2022-02-25 04:58:08 -06:00
2022-02-28 05:16:24 -06:00
- `root` specifies an alternative location to search. Defaults to `FLECKS_CORE_ROOT`.
2022-02-25 04:58:08 -06:00
2023-11-30 21:41:42 -06:00
- `fleck` specifies the fleck owning the configuration. `@flecks/server` owns `server.webpack.config.js`.
2022-02-25 04:58:08 -06:00
Given these considerations, and supposing we had the above variables set like:
```javascript
2023-11-30 21:41:42 -06:00
const filename = 'server.webpack.config.js';
const general = 'webpack.config.js';
2022-02-25 04:58:08 -06:00
const root = '/foo/bar/baz';
const fleck = '@flecks/server';
```
2022-03-09 07:25:58 -06:00
Flecks will then search the following paths top-down until it finds the build configuration:
2022-02-25 04:58:08 -06:00
2023-11-30 21:41:42 -06:00
- `/foo/bar/baz/build/server.webpack.config.js`
- `/foo/bar/baz/build/webpack.config.js`
- `${FLECKS_CORE_ROOT}/build/server.webpack.config.js`
- `${FLECKS_CORE_ROOT}/build/webpack.config.js`
- `@flecks/server/build/server.webpack.config.js`
- `@flecks/server/build/webpack.config.js`