1 | const { resolve } = require('path')
|
2 | const { moduleExists } = require('./utils')
|
3 | const logger = require('./logger')
|
4 |
|
5 | module.exports = function (moduleOptions) {
|
6 | if (!moduleExists('stylelint')) {
|
7 | logger.warn(
|
8 | 'The dependency `stylelint` not found.',
|
9 | 'Please run `yarn add stylelint --dev` or `npm install stylelint --save-dev`'
|
10 | )
|
11 | return
|
12 | }
|
13 |
|
14 | const options = {
|
15 | context: this.options.srcDir,
|
16 | files: [
|
17 | `${this.options.dir.assets}/**/*.{s?(a|c)ss,less,stylus}`,
|
18 | `{components,${this.options.dir.layouts},${this.options.dir.pages}}/**/*.vue`
|
19 | ],
|
20 | ...this.options.stylelint,
|
21 | ...moduleOptions
|
22 | }
|
23 |
|
24 | const filesToWatch = [
|
25 | '.stylelintignore',
|
26 | '.stylelintrc',
|
27 | '.stylelintrc.json',
|
28 | '.stylelintrc.yaml',
|
29 | '.stylelintrc.yml',
|
30 | '.stylelintrc.js',
|
31 | 'stylelint.config.js'
|
32 | ]
|
33 |
|
34 | this.options.watch.push(
|
35 | ...filesToWatch.map(file => resolve(this.options.rootDir, file))
|
36 | )
|
37 |
|
38 | this.extendBuild((config, { isDev, isClient }) => {
|
39 | if (isDev && isClient) {
|
40 | const StylelintPlugin = require('stylelint-webpack-plugin')
|
41 |
|
42 | config.plugins.push(new StylelintPlugin(options))
|
43 | }
|
44 | })
|
45 | }
|
46 |
|
47 | module.exports.meta = require('../package.json')
|