Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change public folder in vue-cli project

Tags:

vue.js

vuejs2

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?

like image 624
Angelo.Hannes Avatar asked Mar 14 '18 12:03

Angelo.Hannes


People also ask

What is the Public folder in Vue?

The public folder is the folder where we have to store static assets, like CSS files and images, media files that don't change over time. In the Vue-cli project, the index file is located within the public folder. Favicon.

Which Vue command inspect and modify the config?

You can also use the vue config command to inspect or modify the global CLI config.

How do I change my Vue title?

This can be simply done by changing the content of the <title> tag in our html code. But for Single-Page Applications, things are a little bit different. When the router changes to a different page component, the title should be changed programmatically using document. title = 'new title' .


1 Answers

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
      })
  }
}
like image 169
John Furr Avatar answered Oct 18 '22 20:10

John Furr