错误:未指定加载器配置 vue.config.js

cou*_*011 5 javascript webpack vue-cli

使用 vue-cli3 并尝试通过 fetch 命令加载 csv 文件,我已经像这样配置了 vue.config.file

module.exports = {
  chainWebpack: config => {
    config.module
      .rule('csv')
      .use('file-loader')
  }
}
Run Code Online (Sandbox Code Playgroud)

并得到错误:

 INFO  Starting development server...
 ERROR  Error: No loader specified
Error: No loader specified
    at Function.normalizeUseItem (D:\Learn\d3\d3-projects\node_modules\webpack\lib\RuleSet.js:274:10)
    at Function.normalizeUse (D:\Learn\d3\d3-projects\node_modules\webpack\lib\RuleSet.js:236:19)
    at use.map (D:\Learn\d3\d3-projects\node_modules\webpack\lib\RuleSet.js:233:33)
    at Array.map (<anonymous>)
    at Function.normalizeUse (D:\Learn\d3\d3-projects\node_modules\webpack\lib\RuleSet.js:233:6)
    at Function.normalizeRule (D:\Learn\d3\d3-projects\node_modules\webpack\lib\RuleSet.js:184:26)
    at rules.map (D:\Learn\d3\d3-projects\node_modules\webpack\lib\RuleSet.js:86:20)
    at Array.map (<anonymous>)
    at Function.normalizeRules (D:\Learn\d3\d3-projects\node_modules\webpack\lib\RuleSet.js:85:17)
    at new RuleSet (D:\Learn\d3\d3-projects\node_modules\webpack\lib\RuleSet.js:80:24)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Run Code Online (Sandbox Code Playgroud)

Set*_*ite 5

根据https://www.npmjs.com/package/webpack-chain,您所做的是创建了一个“命名使用”,但尚未定义关联的加载程序。看起来 config 模块需要按特定顺序调用函数,这可能不是很直观:

  chainWebpack: config => {
    config.module
      .rule("html")            //create a named rule
      .test(/web-components/)  //define the file test
      .use("html-loader")      //create a named use
      .loader("html-loader")   //assign a loader
      .end();                  //back up to define another use, e.g. you could do .end().use()....
}
Run Code Online (Sandbox Code Playgroud)