Server a static pdf - Vue CLI - Webpack - issue Server a static pdf - Vue CLI - Webpack - issue vue.js vue.js

Server a static pdf - Vue CLI - Webpack - issue


You probably don't need Webpack for this: you can just put it in your static folder and link to it <a href="/static/mypdf.pdf">pdf</a>. If you want to go the Webpack route, put it in your src/assets directory and import it and add it to data object:

import pdf from '../assets/mypdf.pdf'//...data: () => ({ pdf })//...

Then use the link in your component:

<a :href="pdf">pdf</a>

You probably added include: paths to the loader config but you didn't define it, instead of modifying your image loader, add a new one for PDFs:

  {    test: /\.(pdf)(\?.*)?$/,    loader: 'url-loader',    options: {      name: utils.assetsPath('[name].[hash:7].[ext]')    }  }

You can change [name].[hash:7].[ext] if you want, say you want to add a pdfs directory in assets instead of using the base assets directory you would use: pdfs/[name].[hash:7].[ext]