2

我试图在我的 webpack 配置文件中包含一个 scss linter。但是每次我运行“npm run start”时,我的控制台都会打印以下错误消息:

错误:找不到模块'stylelint'

插件已安装,我的 webpack.config.dev.js 如下所示:

const merge = require('webpack-merge')
const webpack = require('webpack')
const common = require('./webpack.config.common')
const user = require('./scripts/utils/format-config')(require('./main.config.js'))
var styleLintPlugin = require('stylelint-webpack-plugin');

const cssLoaders = (
  [
    {
      loader: 'style-loader',
      options: {
        sourceMap: true,
        singleton: true // avoid CSS Flashing
      }
    }
  ].concat(common.CSSLoaders)
)

// append resolve-url-loader before the preprocessor loader so that
// we can avoid broken relative url with the dev server
if (user.css.preprocessorLoader) {
  for (let i = 0; i < cssLoaders.length; i++) {
    const obj = cssLoaders[i]
    if (obj.loader !== user.css.preprocessorLoader) continue
    cssLoaders.splice(i, 0,
      {
        loader: 'resolve-url-loader',
        options: { sourceMap: true }
      }
    )
    break
  }
}

const devConfig = {
  mode: 'development',
  entry: user.entries,
  module: {
    rules: [
      {
        test: user.css.sourceRegexExt,
        use: cssLoaders
      },
      {
        test: /\.(svg|png|jpg|gif|ttf|otf|woff|woff2|eot)$/,
        use: [
          {
            loader: 'file-loader',
            options: {}
          }
        ]
      }
    ]
  },
  plugins: [
    new webpack.NoEmitOnErrorsPlugin(),
    new webpack.NamedModulesPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new styleLintPlugin({
      configFile: '.stylelintrc',
      context: 'src',
      files: '**/*.scss',
      failOnError: false,
      quiet: false,
      syntax: 'scss',
    }),
  ],
  devtool: '#eval-source-map'
}

module.exports = merge(common.webpack, devConfig)

我会为每一个答案感到高兴=)我会为每一个答案感到高兴=)

4

1 回答 1

0

这在这里解决了我的问题。检查链接: https ://github.com/webpack-contrib/stylelint-webpack-plugin/issues/166

于 2018-09-17T14:08:40.717 回答