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

时间:2018-04-01 06:01:36

标签: javascript webpack vue-cli

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

module.exports = {
  chainWebpack: config => {
    config.module
      .rule('csv')
      .use('file-loader')
  }
}

并收到错误:

 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.

1 个答案:

答案 0 :(得分:0)

根据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()....
}