在vue-cli 3中配置webpack配置文件

时间:2018-04-01 05:30:01

标签: javascript webpack vue-cli

我刚刚使用命令“vue create my-project”创建了一个基础项目现在我正在使用fetch API获取csv文件,问题是因为csv文件的url是错误的,它总是返回我index.html文件而不是错误。这是我的代码:

const data = await fetch('/url/path/to/my.csv')
const val = data.text()
// here val always have the same content as of index.html

我该如何解决?

2 个答案:

答案 0 :(得分:3)

由于此问题的标题是关于“在vue-cli 3中配置webpack配置文件”,让我告诉您可以自定义您的webpack配置,只需更改 vue.config.js 即可自动包含在项目根目录中vue create my-project,如下所示:

// vue.config.js

module.exports = {
  configureWebpack: {
    // It will be merged into the final Webpack config
    plugins: [
      new MyWebpackPluginExample()
    ]
  }
}

答案 1 :(得分:0)

如果您想使用fetch来获取json文件,则必须为该文件设置服务器,至少在生产环境中是这样。

但是在客户端,您可以将csv文件导入到webpack模块中。 要安装csv loader

void

将加载程序添加到monaco.editor.create(document.getElementById("monaco"), { language: "javascript", // I thought specifying "javascript" instead of "typescript" should include only the javascript features? }); 的{​​{1}}文件中,其中包含:

npm install csv-loader --save-dev

现在将文件加载到模块中:

webpack.base.config.js

并使用build/webpack.base.config.js变量访问该变量。