1 | # @megalo/cli-plugin-mp
|
2 |
|
3 | > eslint plugin for megalo-cli
|
4 |
|
5 | ## 注入的命令
|
6 |
|
7 | - **`megalo-cli-service lint`**
|
8 |
|
9 | ```
|
10 | Usage: megalo-cli-service lint [options] [...files]
|
11 |
|
12 | Options:
|
13 |
|
14 | --format [formatter] specify formatter (default: codeframe)
|
15 | --no-fix do not fix errors
|
16 | --max-errors specify number of errors to make build failed (default: 0)
|
17 | --max-warnings specify number of warnings to make build failed (default: Infinity)
|
18 | ```
|
19 |
|
20 | 检查提示以及修复文件格式。 如果没有特别指定文件或目录,默认情况下它会检查 `src` 和 `test` 目录下的所有文件
|
21 |
|
22 | 另外 [ESLint CLI options](https://eslint.org/docs/user-guide/command-line-interface#options) 这里的选项也是支持的.
|
23 |
|
24 | ## 配置
|
25 |
|
26 | ESLint可以通过 `.eslintrc` 或 `package.json` 中的 `eslintConfig` 字段进行配置。
|
27 |
|
28 | 默认情况下启用 `eslint-loader` 进行开发时的保存。 可以使用 `megalo.config.js` 中的 `lintOnSave` 选项禁用它:
|
29 |
|
30 | ``` js
|
31 | module.exports = {
|
32 | lintOnSave: false
|
33 | }
|
34 | ```
|
35 |
|
36 | 设置为 `true` 时,`eslint-loader` 会将 lint 错误输出为编译警告。默认情况下,警告仅仅会被输出到命令行,且不会使得编译失败。
|
37 |
|
38 | 如果你希望让 `lint` 错误在开发时直接显示在浏览器中,你可以使用 `lintOnSave: 'error'`。这会强制 `eslint-loader` 将 `lint` 错误输出为编译错误,同时也意味着 `lint` 错误将会导致编译失败。
|
39 |
|
40 | 或者,你也可以通过设置让浏览器 `overlay` 同时显示警告和错误:
|
41 |
|
42 | ``` js
|
43 | // megalo.config.js
|
44 | module.exports = {
|
45 | // 编译小程序不支持该选项
|
46 | devServer: {
|
47 | overlay: {
|
48 | warnings: true,
|
49 | errors: true
|
50 | }
|
51 | }
|
52 | }
|
53 | ```
|
54 |
|
55 | 当 `lintOnSave` 是一个 truthy 的值时,`eslint-loader` 在开发和生产构建下都会被启用。如果你想要在生产构建时禁用 `eslint-loader`,你可以用如下配置:
|
56 |
|
57 | ``` js
|
58 | // megalo.config.js
|
59 | module.exports = {
|
60 | lintOnSave: process.env.NODE_ENV !== 'production'
|
61 | }
|
62 | ```
|
63 |
|
64 | ## 修改 webpack-chain 规则
|
65 |
|
66 | - `config.module.rule('eslint')`
|
67 | - `config.module.rule('eslint').use('eslint-loader')`
|