[Vuejs]-Pdf loader for nuxt.js

3👍

I had the same issue with my downloadable pdf files and solved it by moving the download’s folder to the static directory.

0👍

You are able to archive this by extending the build config in the nuxt.config.js.

module.exports = {
  build: {
    extend(config) {
      // Find the rule which contains a assets file extension
      const assetsLoader = config.module.rules.find(rule => rule.test.test('.png'));

      // Overwrite the test regex and add `pdf`
      assetsLoader.test = /\.(png|jpe?g|gif|svg|webp|pdf)$/i;

      return config;
    },
  },
};

0👍

One of the ways to resolve it is by loading the instance of jspdf in the client-side.

if(process.client) {
  const jsPDF = require('jspdf');
  require('jspdf-autotable');

  let doc = new jsPDF();
  // ...your code
}

As per the Nuxt Documentation, check this out Window Document Undefined.

Leave a comment