【问题标题】:Change public folder in vue-cli project更改 vue-cli 项目中的公用文件夹
【发布时间】:2018-03-14 12:54:57
【问题描述】:

当我运行 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 中覆盖它?

【问题讨论】:

  • 你应该看看你的webpack.config.json文件

标签: vue.js vuejs2


【解决方案1】:

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

【讨论】:

  • 这行得通,但路径必须以./ 开头,否则你会得到一些错误module could not be resolved 所以./path/to/index.html
猜你喜欢
  • 2021-11-21
  • 2011-08-11
  • 2020-09-17
  • 2020-05-22
  • 2018-07-04
  • 2020-07-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多