-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.js
57 lines (52 loc) · 1.96 KB
/
index.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
50
51
52
53
54
55
56
57
const StyleLintPlugin = require('stylelint-webpack-plugin');
const CodeframeFormatter = require('stylelint-codeframe-formatter');
const lint = require('./lint');
module.exports = (api, projectOptions) => {
const { pluginOptions: { lintStyleOnBuild, stylelint } } = projectOptions;
if (lintStyleOnBuild) {
api.chainWebpack((webpackConfig) => {
/* eslint-disable indent */
webpackConfig
.plugin('stylelint')
.use(StyleLintPlugin, [Object.assign({
failOnError: lintStyleOnBuild === '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);
// eslint-disable-next-line global-require
plugin = require('./stylelintError')[pluginName];
} catch (e) {
return;
}
plugin && plugins.push(plugin);
});
return [options];
});
/* eslint-enable indent */
});
}
api.registerCommand('lint:style', {
description: 'lint and fix source files',
usage: 'vue-cli-service lint:style [options] [...files]',
options: {
'--no-fix': 'do not fix errors',
'--options': 'display stylelint options',
},
details: 'Autofixing is an experimental feature, see https://stylelint.io/user-guide/cli/#autofixing-errors',
}, (args) => { lint(api, args, stylelint); });
};