# @confy/core

> Build configurations for painless, modern JavaScript development.

Latest version **0.7.0** (published 2021-03-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @confy/core
pnpm add @confy/core
yarn add @confy/core
bun add @confy/core
```

Provides the command `confy-core`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.0 |
| Published | 2021-03-23 |
| First published | 2019-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.6 |
| Dependencies | 38 |
| Unpacked size | 35.1 KB |
| Known vulnerabilities | 0 (+7 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Felix Laukel |
| Maintainers | coldi |
| Keywords | confy, build, config, project, generator |

## Links

- npm: https://www.npmjs.com/package/@confy/core
- Repository: https://github.com/coldi/confy
- Homepage: https://github.com/coldi/confy#readme
- Issues: https://github.com/coldi/confy/issues
- npm.io page: https://npm.io/package/@confy/core

## Dependencies (38)

- [ip](https://npm.io/package/ip.md) ^1.1.5
- [glob](https://npm.io/package/glob.md) ^7.1.2
- [jest](https://npm.io/package/jest.md) ^24.5.0
- [chalk](https://npm.io/package/chalk.md) ^2.3.0
- [yargs](https://npm.io/package/yargs.md) ^10.0.0
- [eslint](https://npm.io/package/eslint.md) ^5.15.0
- [core-js](https://npm.io/package/core-js.md) ^3.0.0
- [webpack](https://npm.io/package/webpack.md) ~4.46.0
- [get-port](https://npm.io/package/get-port.md) ^5.0.0
- [prettier](https://npm.io/package/prettier.md) ^1.16.4
- [invariant](https://npm.io/package/invariant.md) ^2.2.2
- [babel-core](https://npm.io/package/babel-core.md) 7.0.0-bridge.0
- [babel-jest](https://npm.io/package/babel-jest.md) ^24.5.0
- [css-loader](https://npm.io/package/css-loader.md) ^2.1.0
- [url-loader](https://npm.io/package/url-loader.md) ^1.1.0
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.4.0
- [file-loader](https://npm.io/package/file-loader.md) ^3.0.0
- [autoprefixer](https://npm.io/package/autoprefixer.md) ^9.0.0
- [babel-eslint](https://npm.io/package/babel-eslint.md) ^10.0.0
- [babel-loader](https://npm.io/package/babel-loader.md) ^8.0.0
- [style-loader](https://npm.io/package/style-loader.md) ^0.23.0
- [console-clear](https://npm.io/package/console-clear.md) ^1.0.0
- [eslint-loader](https://npm.io/package/eslint-loader.md) ^2.1.0
- [postcss-loader](https://npm.io/package/postcss-loader.md) ^3.0.0
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.4.0
- [identity-obj-proxy](https://npm.io/package/identity-obj-proxy.md) ^3.0.0
- [webpack-dev-server](https://npm.io/package/webpack-dev-server.md) ~3.2.0
- [copy-webpack-plugin](https://npm.io/package/copy-webpack-plugin.md) ^5.0.0
- [html-webpack-plugin](https://npm.io/package/html-webpack-plugin.md) ^3.2.0
- [clean-webpack-plugin](https://npm.io/package/clean-webpack-plugin.md) ^2.0.0
- [eslint-plugin-import](https://npm.io/package/eslint-plugin-import.md) ^2.16.0
- [eslint-config-prettier](https://npm.io/package/eslint-config-prettier.md) ^4.1.0
- [eslint-plugin-prettier](https://npm.io/package/eslint-plugin-prettier.md) ^3.0.1
- [mini-css-extract-plugin](https://npm.io/package/mini-css-extract-plugin.md) ^0.5.0
- [eslint-config-airbnb-base](https://npm.io/package/eslint-config-airbnb-base.md) ^13.1.0
- [@babel/plugin-syntax-import-meta](https://npm.io/package/@babel/plugin-syntax-import-meta.md) ^7.2.0
- [@babel/plugin-syntax-dynamic-import](https://npm.io/package/@babel/plugin-syntax-dynamic-import.md) ^7.2.0
- [@babel/plugin-proposal-class-properties](https://npm.io/package/@babel/plugin-proposal-class-properties.md) ^7.4.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.7.0 (latest) — 2021-03-23
- 1.0.0-alpha.0 — 2021-03-23
- 0.5.2 — 2019-06-04
- 0.5.1 — 2019-05-19
- 0.5.0 — 2019-05-10
- 0.4.0 — 2019-04-28
- 0.3.6 — 2019-04-20
- 0.3.5 — 2019-04-13
- 0.3.4 — 2019-04-11
- 0.3.3 — 2019-04-09
- 0.3.2 — 2019-04-04
- 0.3.1 — 2019-04-02
- 0.3.0 — 2019-03-28
- 0.2.0 — 2019-03-24
- 0.1.1 — 2019-03-24

## README

# @confy/core

The core package provides the base configuration functionality and a CLI that you can use in your NPM scripts.

You can [read more about Confy here](https://github.com/coldi/confy).

## CLI commands

### `confy-core init --env=development`

Writes config files to your project folder.
This is useful if you want to enable ESLint support in your IDE.<br>
So at the moment, running this command is only necessary when changing any ESLint or Prettier related configuration in `.apprc.js`.<br>

_Config files are also updated on every other command._

### `confy-core start --env=development`

Runs your app in development mode using Webpack DevServer.<br>
Open [http://localhost:3000/](http://localhost:3000/) to view it in the browser.

### `confy-core build --env=production`

Builds your files for production to the `build` folder (default).<br>
The result is minified, optimized and ready to be deployed.

### `confy-core build --watch --env=production`

Same as above but watches for file changes and performs new builds on the fly. Can be useful for legacy projects.

### `confy-core test --env=test`

Let Jest run your tests.

It will look for them in `*.test.js`, `*.spec.js` files or `__test__/*` folders.

### `confy-core show-config --env=development`

Prints the configuration settings for `development` or `production` to the console.

## Configuration

### Options

Changing options in `.apprc.js` is one (quick!) way to adjust the configuration according to your project needs.

Below you find a list of all available options with their default values.

```js
// .apprc.js

module.exports = {
  options: {
    // Define directory for your project files.
    srcDir: 'src',

    // Define the directory for your static files.
    assetsDir: 'assets', // Relative to srcDir

    // Define your output directory.
    buildDir: 'build',

    // Define files for main bundle.
    // Path is relative to srcDir.
    // May contain your css entry file as well, so you don't have to import it.
    entryFiles: ['index'],

    // Set js output filename in webpack.output
    jsOutputFile: '[name].bundle.js',

    // Set css output filename for MiniCssExtractPlugin
    cssOutputFile: 'style.css',

    // Set css filename for dynamic chunks using MiniCssExtractPlugin
    cssChunkFile: '[id].css',

    // Set path to html template.
    htmlTemplate: 'index.html', // Relative to srcDir

    // Define page title.
    title: 'New App',

    // Code style indention
    tabWidth: 4,

    // Hostname for webpack dev server.
    host: '0.0.0.0',

    // Port for webpack dev server.
    port: 3000,

    // List of supported browsers for babel-preset-env and postcss autoprefixer.
    browsersList: [
      '>2.5%',
      'last 4 chrome versions',
      'last 4 ff versions',
      'last 2 edge versions',
      'last 2 ios versions',
      'last 2 safari versions',
      'not ie 11',
    ],

    // The file size in bytes under which the url-loader kicks in
    // and base64-inlines your required files.
    // E.g.: When set to 5000, all files below 5KB will be inlined.
    inlineFileSize: -1, // Use -1 to disable, 0 for no limit at all

    // BELOW SHOULD NOT BE CHANGED IN MOST CASES!

    // Environment boolean flags.
    // Defines if we are in development mode (true) or production (false).
    devMode: process.env.NODE_ENV === 'development',

    // Defines if we are in test mode (true) or not (false).
    testMode: process.env.NODE_ENV === 'test',
  },
};
```

> NOTE: Presets may introduce more options when necessary.

### How it works

Confy has the concept of "options", "addons" and "runners".<br>
Options can be used to make quick changes to your config because they are referenced inside the tools.
Addons and runners are used to define two groups of tools within Confy.

Addons are all the tools that runners need to run your code.<br>
Therefore addons in `.apprc.js` contain the configurations for Babel and ESLint. Maybe more in the future.

Runners eventually run your code and do things with it, utilizing addons.
These runners are Webpack and Jest..<br>
Webpack bundles your code. Jest runs your tests. They do not have much in common, **except** sharing options and addons as they need.

Here is a rough explanation of how Confy's extendable configuration concept works:

- First Confy gathers all `.apprc.js` files by looking inside your project root and resolving any presets that you added.
- It then merges all configurations into one, step by step, in this order `root -> [...presets] -> project`:
  - It starts by merging all **options** in that order.<br>
  - It continues by merging all **addons** in that order.
  - Finally it merges all **runners** in that order.
- The resulting configuration object is the one that is used inside all the tools when they are eventually executed.

> Note that every options, addons or runners section in `.apprc.js` can receive the current state of the merged configuration, when defined as a function.

Here is a practical overview of different approaches on how to update a configuration:

```js
// .apprc.js in your project

module.exports = {
  // options, addons and runners always receive the whole config object when defined as a function.
  addons: (currentConfig) => ({
    eslint: {
      // When extending arrays you should use functions and spread the previous items in.
      presets: (presets) => [...presets, 'some-preset'],

      // Mutating the passed argument is also perfectly fine.
      plugins: (plugins) => {
        plugins.push('some-plugin');
        return plugins;
      }

      // Objects on the other hand get shallow merged with the previous value automatically.
      rules: {
        'some-rule': 'warn',
      },

      // Therefore *if* you really want to overwrite an object value
      // use a function and don't spread previous values.
      // Use with caution, though!
      something: () => ({
        key: 'this will overwrite `something` completely',
      }),
    },
  }),
};
```

### Advanced usage

To get an idea of how you can adjust Confy in order to work with a library like React, the [@confy/preset-react](https://github.com/coldi/confy/tree/master/packages/preset-react/apprc.js) itself is a good starting point.

---
_Source: https://npm.io/package/@confy/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
