繁体   English   中英

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

[英]Change public folder in vue-cli project

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

[copy-webpack-plugin]无法在'path \\ to \\ project \\ public'中找到'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中覆盖它?

这适用于我使用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
      })
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM