简体   繁体   中英

Change public folder in vue-cli project

When I run npm run build I get the following error message.

[copy-webpack-plugin] unable to locate 'path\\to\\project\\public' at 'path\\to\\project\\public'

I moved the public folder to src/main/resources/public . However I can't find a config to change the path. I think the relevant code is in 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']
    }]])

How do I override this in vue.config.js?

This works for me using vue-cli 3.0. Just add it to your vue.config.js file.

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

Though this might be more technically correct.

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

Edit:

Actually this would be the preferred way of doing this so that none of the other defaults are overwritten.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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