forked from luoxue-victor/workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyleLintPlugin.js
49 lines (47 loc) · 1.32 KB
/
styleLintPlugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// [stylelint 配置]
module.exports = ({
config,
options: {
stylelint: {
lintOnSave = false,
extensions = ['vue', 'htm', 'html', 'css', 'sss', 'less', 'scss']
} = {}
}
}) => {
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/**/*.{${extensions.join()}}`],
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]
})
}
}