module.js 1.2 KB

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