webpack-resolve-alias to resolve dependecy's sub-dependency

Viewed 461

I'm sort of stuck with one problem and googling it for about three hours brought me nowhere.

Here's the problem. I'm trying to develop my own custom PDF viewer based on PDF.JS lib. Officially it is distributed on npm as pdfjs-dist package. However I need to extend a few classes that are not accessible in pdfjs-dist. So I npm install'ed or yarn add'ed the original repo https://github.com/mozilla/pdf.js.git. This way I have access to classes I need. Inside pdf.js there are core lib that is stored in pdf.js/src/ and a pdf-viewer app that is stored in pdf.js/web/.

Inside that pdf.js/web/ app core lib (pdf.js) is referenced via pdfjs-lib alias that is resolved to pdf.js/src/ during pdf.js inner build process by gulp.

For example pdf.js/web/base_viewer.js:

import { AnnotationLayerBuilder } from './annotation_layer_builder';
import { createPromiseCapability } from 'pdfjs-lib';
import { PDFPageView } from './pdf_page_view';

So now I'm trying to import that pdf.js/web/base_viewer.js in my app that is using latest Webpack 4 (I guess), and this pdfjs-lib sub-dependency is not resolved.

I've tried webpack's resolve-alias mechanism (https://webpack.js.org/configuration/resolve/):

    resolve: {
      alias: {
        'pdfjs-lib': path.resolve(__dirname, './node_modules/pdf.js/src/')
      },
    }

...but looks like it resolves dependencies only of my own App, but not sub-dependencies of my dependency.

Just in case I'm building Vue 3.0 app using vue-cli and access webpack config this way: https://cli.vuejs.org/guide/webpack.html, but don't think it matters.

Any help from Webpack gurus here?

Thanks.

0 Answers
Related