在vue-cli项目中更改公用文件夹

时间:2018-03-14 12:54:57

标签: vue.js vuejs2

当我运行npm run build时,收到以下错误消息。

  

[copy-webpack-plugin]无法找到' path \ to \ project \ public' at' path \ to \ project \ public'

我将public文件夹移至src/main/resources/public。但是,我无法找到更改路径的配置。我认为相关代码位于node_modules\@vue\cli-service\lib\config\app.js

// copy static assets in public/
webpackConfig
  .plugin('copy')
    .use(require('copy-webpack-plugin'), [[{
      from: api.resolve('public'),
      to: api.resolve(options.outputDir),
      ignore: ['index.html', '.DS_Store']
    }]])

如何在vue.config.js中覆盖它?

1 个答案:

答案 0 :(得分:3)

这适用于我使用vue-cli 3.0。只需将其添加到您的vue.config.js文件中即可。

module.exports = {
  chainWebpack: config => {
    config
      .plugin('html')
      .tap(args => {
        return [{template: '/path/to/index.html'}]
      })
  }
}

虽然这可能在技术上更正确。

module.exports = {
  chainWebpack: config => {
    config
      .plugin('html')
      .tap(args => {
        args[0] = {
            template: '/path/to/index.html'
        }
        return args
      })
  }
}

编辑:

实际上,这是首选方法,这样就不会覆盖其他任何默认值。

module.exports = {
  chainWebpack: config => {
    config
      .plugin('html')
      .tap(args => {
        args[0].template = '/path/to/index.html'
        return args
      })
  }
}
相关问题