Skip to content

Instantly share code, notes, and snippets.

@aquilesb
Created July 10, 2019 02:39
Show Gist options
  • Save aquilesb/f65bda1a8f96e82f73e6f95cedb09625 to your computer and use it in GitHub Desktop.
Save aquilesb/f65bda1a8f96e82f73e6f95cedb09625 to your computer and use it in GitHub Desktop.
How to add pdf loader to vue-cli's project
module.exports = {
chainWebpack: config => {
config.module.rule('pdf')
.test(/\.(pdf)(\?.*)?$/)
.use('file-loader')
.loader('file-loader')
.options({
name: 'assets/pdf/[name].[hash:8].[ext]'
})
}
}
@aquilesb
Copy link
Author

aquilesb commented Apr 2, 2020

What should I do in case if I have babel.config.js?

I'm not sure what you want to achieve. This is related to add a pdf loader in a project using vue-cli. As the project itself does not have a webpack config file you have to change in the vue.config.js file. Is not required to do anything on babel.config.js

@WangNingning1994
Copy link

Dude, you saved my life!

@Joshua-Nweze
Copy link

I added the code you wrote but it isn't working
Here's what my config file looks like

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  chainWebpack: config => {
    config.module.rule('pdf')
      .test(/\.(pdf)(\?.*)?$/)
      .use('file-loader')
        .loader('file-loader')
        .options({
          name: 'assets/pdf/[name].[hash:8].[ext]'
        })

  }
})

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment