|
| 1 | +# Default build configuration by Grafana |
| 2 | + |
| 3 | +**This is an auto-generated directory and is not intended to be changed! ⚠️** |
| 4 | + |
| 5 | +The `.config/` directory holds basic configuration for the different tools |
| 6 | +that are used to develop, test and build the project. In order to make it updates easier we ask you to |
| 7 | +not edit files in this folder to extend configuration. |
| 8 | + |
| 9 | +## How to extend the basic configs? |
| 10 | + |
| 11 | +Bear in mind that you are doing it at your own risk, and that extending any of the basic configuration can lead |
| 12 | +to issues around working with the project. |
| 13 | + |
| 14 | +### Extending the ESLint config |
| 15 | + |
| 16 | +Edit the `.eslintrc` file in the project root in order to extend the ESLint configuration. |
| 17 | + |
| 18 | +**Example:** |
| 19 | +```json |
| 20 | +{ |
| 21 | + "extends": "./.config/.eslintrc", |
| 22 | + "rules": { |
| 23 | + "react/prop-types": "off" |
| 24 | + } |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +### Extending the Prettier config |
| 31 | + |
| 32 | +Edit the `.prettierrc.js` file in the project root in order to extend the Prettier configuration. |
| 33 | + |
| 34 | +**Example:** |
| 35 | +```javascript |
| 36 | +module.exports = { |
| 37 | + // Prettier configuration provided by Grafana scaffolding |
| 38 | + ...require("./.config/.prettierrc.js"), |
| 39 | + |
| 40 | + semi: false, |
| 41 | +}; |
| 42 | +``` |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +### Extending the Jest config |
| 47 | + |
| 48 | +There are two configuration in the project root that belong to Jest: `jest-setup.js` and `jest.config.js`. |
| 49 | + |
| 50 | +**`jest-setup.js`:** A file that is run before each test file in the suite is executed. We are using it to |
| 51 | +set up the Jest DOM for the testing library and to apply some polyfills. ([link to Jest docs](https://jestjs.io/docs/configuration#setupfilesafterenv-array)) |
| 52 | + |
| 53 | +**`jest.config.js`:** The main Jest configuration file that is extending our basic Grafana-tailored setup. ([link to Jest docs](https://jestjs.io/docs/configuration)) |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +### Extending the TypeScript config |
| 58 | + |
| 59 | +Edit the `tsconfig.json` file in the project root in order to extend the TypeScript configuration. |
| 60 | + |
| 61 | +**Example:** |
| 62 | +```json |
| 63 | +{ |
| 64 | + "extends": "./.config/tsconfig.json", |
| 65 | + "compilerOptions": { |
| 66 | + "preserveConstEnums": true |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +### Extending the Webpack config |
| 74 | + |
| 75 | +Follow these steps to extend the basic Webpack configuration that lives under `.config/`: |
| 76 | + |
| 77 | +#### 1. Create a new Webpack configuration file |
| 78 | + |
| 79 | +Create a new config file that is going to extend the basic one provided by Grafana. |
| 80 | +It can live in the project root, e.g. `webpack.config.ts`. |
| 81 | + |
| 82 | +#### 2. Merge the basic config provided by Grafana and your custom setup |
| 83 | +We are going to use [`webpack-merge`](https://github.com/survivejs/webpack-merge) for this. |
| 84 | + |
| 85 | +```typescript |
| 86 | +// webpack.config.ts |
| 87 | +import type { Configuration } from 'webpack'; |
| 88 | +import { merge } from 'webpack-merge'; |
| 89 | +import grafanaConfig from './.config/webpack/webpack.config'; |
| 90 | + |
| 91 | +const config = async (env): Promise<Configuration> => { |
| 92 | + const baseConfig = await grafanaConfig(env); |
| 93 | + |
| 94 | + return merge(baseConfig, { |
| 95 | + // Add custom config here... |
| 96 | + output: { |
| 97 | + asyncChunks: true, |
| 98 | + }, |
| 99 | + }); |
| 100 | +}; |
| 101 | + |
| 102 | +export default config; |
| 103 | + |
| 104 | +``` |
| 105 | + |
| 106 | +#### 3. Update the `package.json` to use the new Webpack config |
| 107 | + |
| 108 | +We need to update the `scripts` in the `package.json` to use the extended Webpack configuration. |
| 109 | + |
| 110 | +**Update for `build`:** |
| 111 | +```diff |
| 112 | +-"build": "webpack -c ./.config/webpack/webpack.config.ts --env production", |
| 113 | ++"build": "webpack -c ./webpack.config.ts --env production", |
| 114 | +``` |
| 115 | + |
| 116 | +**Update for `dev`:** |
| 117 | +```diff |
| 118 | +-"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development", |
| 119 | ++"dev": "webpack -w -c ./webpack.config.ts --env development", |
| 120 | +``` |
0 commit comments