-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
luoxue
committed
Dec 9, 2019
1 parent
57155ce
commit 3d7143a
Showing
17 changed files
with
172 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ module.exports = { | |
}, | ||
extends: [ | ||
'plugin:vue/essential', | ||
'eslint:recommended', | ||
'standard' | ||
], | ||
rules: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: 'stylelint-config-standard' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin') | ||
|
||
module.exports = ({ config }) => { | ||
const { transformer, formatter } = require('../util/resolveLoaderError') | ||
return () => { | ||
config.plugin('error') | ||
.use(FriendlyErrorsWebpackPlugin) | ||
config.plugin('friendly-errors') | ||
.use(require('@soda/friendly-errors-webpack-plugin'), [{ | ||
additionalTransformers: [transformer], | ||
additionalFormatters: [formatter] | ||
}]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module.exports = ({ config, options: { stylelint: { lintOnSave = false, extensions } = {} }, api }) => { | ||
const StyleLintPlugin = require('stylelint-webpack-plugin') | ||
const CodeframeFormatter = require('stylelint-codeframe-formatter') | ||
const stylelint = [] | ||
return () => { | ||
if (!lintOnSave) return | ||
config | ||
.plugin('stylelint') | ||
.use(StyleLintPlugin, [Object.assign({ | ||
failOnError: lintOnSave === 'error', | ||
files: ['src/**/*.{vue,htm,html,css,sss,less,scss}'], | ||
formatter: CodeframeFormatter | ||
}, stylelint)]) | ||
.end() | ||
.plugin('friendly-errors') | ||
.tap(([options]) => { | ||
['Transformers', 'Formatters'].forEach((name) => { | ||
const optKey = `additional${name}` | ||
let plugins | ||
if (Array.isArray(options[optKey])) { | ||
plugins = options[optKey] | ||
} else { | ||
plugins = [] | ||
Object.assign(options, { [optKey]: plugins }) | ||
} | ||
|
||
let plugin | ||
try { | ||
const pluginName = name.toLowerCase().slice(0, -1) | ||
plugin = require('./stylelintError')[pluginName] | ||
} catch (e) { | ||
return | ||
} | ||
|
||
plugin && plugins.push(plugin) | ||
}) | ||
return [options] | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# 添加 stylelint | ||
|
||
### 配置 stylelintrc | ||
|
||
使用 stylelint-config-standard 插件 | ||
|
||
.stylelintrc.js | ||
|
||
```js | ||
module.exports = { | ||
root: true, | ||
extends: 'stylelint-config-standard' | ||
} | ||
``` | ||
|
||
### 配置 stylelint 插件 | ||
|
||
```js | ||
module.exports = ({ config, options: { stylelint: { lintOnSave = false, extensions } = {} }, api }) => { | ||
const StyleLintPlugin = require('stylelint-webpack-plugin') | ||
const CodeframeFormatter = require('stylelint-codeframe-formatter') | ||
const stylelint = [] | ||
return () => { | ||
config | ||
.plugin('stylelint') | ||
.use(StyleLintPlugin, [Object.assign({ | ||
failOnError: lintOnSave === 'error', | ||
files: ['src/**/*.{vue,htm,html,css,sss,less,scss}'], | ||
formatter: CodeframeFormatter | ||
}, stylelint)]) | ||
} | ||
} | ||
``` | ||
|
||
### 代码提交检查 | ||
|
||
```json | ||
{ | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.{vue,htm,html,css,sss,less,scss}": [ | ||
"webpack-box lint stylelint", | ||
"git add" | ||
], | ||
"*.{js,jsx}": [ | ||
"webpack-box lint eslint", | ||
"git add" | ||
] | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* app.css */ | ||
.test { | ||
font-size: 60px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
color: red; | ||
display: flex; | ||
background-color: orange; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* index.less */ | ||
.test { | ||
width: 300px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ | |
|
||
.asd { | ||
height: 100px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* index.scss */ | ||
.test { | ||
height: 300px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const chalk = require('chalk') | ||
|
||
const rules = [ | ||
{ | ||
type: 'cant-resolve-loader', | ||
re: /Can't resolve '(.*loader)'/, | ||
msg: (e, match) => ( | ||
`Failed to resolve loader: ${chalk.yellow(match[1])}\n` + | ||
'You may need to install it.' | ||
) | ||
} | ||
] | ||
|
||
exports.transformer = error => { | ||
if (error.webpackError) { | ||
const message = typeof error.webpackError === 'string' | ||
? error.webpackError | ||
: error.webpackError.message || '' | ||
for (const { re, msg, type } of rules) { | ||
const match = message.match(re) | ||
if (match) { | ||
return Object.assign({}, error, { | ||
// type is necessary to avoid being printed as defualt error | ||
// by friendly-error-webpack-plugin | ||
type, | ||
shortMessage: msg(error, match) | ||
}) | ||
} | ||
} | ||
// no match, unknown webpack error without a message. | ||
// friendly-error-webpack-plugin fails to handle this. | ||
if (!error.message) { | ||
return Object.assign({}, error, { | ||
type: 'unknown-webpack-error', | ||
shortMessage: message | ||
}) | ||
} | ||
} | ||
return error | ||
} | ||
|
||
exports.formatter = errors => { | ||
errors = errors.filter(e => e.shortMessage) | ||
if (errors.length) { | ||
return errors.map(e => e.shortMessage) | ||
} | ||
} |