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

9
当我运行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 文件即可。 - soju
1个回答

10

这对我来说很有效,使用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
      })
  }
}

2
这个可以运行,但路径必须以 ./ 开头,否则会出现一些错误,例如 无法解析模块,所以应该使用 ./path/to/index.html - Andy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接