From 265fd34f935fd83ff58369534c073289b61ccf7d Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Wed, 5 Jan 2022 13:58:59 +0100 Subject: [PATCH] Make instructions for copying cMaps work with Yarn PnP, update sample and test suites --- README.md | 3 ++- sample/webpack4/webpack.config.js | 4 +++- sample/webpack5/webpack.config.js | 4 +++- test/webpack.config.js | 4 +++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 275d90cdc..19f499e9d 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,7 @@ npm install copy-webpack-plugin --save-dev Now, in your Webpack config, import the plugin: ```js +import path from 'path'; import CopyWebpackPlugin from 'copy-webpack-plugin'; ``` @@ -181,7 +182,7 @@ and in `plugins` section of your config, add the following: ```js new CopyWebpackPlugin([ { - from: 'node_modules/pdfjs-dist/cmaps/', + from: path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'cmaps'), to: 'cmaps/' }, ]), diff --git a/sample/webpack4/webpack.config.js b/sample/webpack4/webpack.config.js index 41e63b889..97b0554f4 100644 --- a/sample/webpack4/webpack.config.js +++ b/sample/webpack4/webpack.config.js @@ -6,6 +6,8 @@ const HtmlWebpackPlugin = require('html-webpack-plugin'); const isProduction = process.env.NODE_ENV === 'production'; +const cMapsDir = path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'cmaps'); + module.exports = { mode: isProduction ? 'production' : 'development', bail: isProduction, @@ -56,7 +58,7 @@ module.exports = { new CopyWebpackPlugin({ patterns: [ { from: './sample.pdf' }, - { from: 'node_modules/pdfjs-dist/cmaps/', to: 'cmaps/' }, + { from: cMapsDir, to: 'cmaps/' }, ], }), ], diff --git a/sample/webpack5/webpack.config.js b/sample/webpack5/webpack.config.js index 41e63b889..97b0554f4 100644 --- a/sample/webpack5/webpack.config.js +++ b/sample/webpack5/webpack.config.js @@ -6,6 +6,8 @@ const HtmlWebpackPlugin = require('html-webpack-plugin'); const isProduction = process.env.NODE_ENV === 'production'; +const cMapsDir = path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'cmaps'); + module.exports = { mode: isProduction ? 'production' : 'development', bail: isProduction, @@ -56,7 +58,7 @@ module.exports = { new CopyWebpackPlugin({ patterns: [ { from: './sample.pdf' }, - { from: 'node_modules/pdfjs-dist/cmaps/', to: 'cmaps/' }, + { from: cMapsDir, to: 'cmaps/' }, ], }), ], diff --git a/test/webpack.config.js b/test/webpack.config.js index 296b4aad5..62bdb1cae 100644 --- a/test/webpack.config.js +++ b/test/webpack.config.js @@ -8,6 +8,8 @@ const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin' const isProduction = process.env.NODE_ENV === 'production'; const isDevelopment = !isProduction; +const cMapsDir = path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'cmaps'); + module.exports = { mode: isProduction ? 'production' : 'development', bail: isProduction, @@ -67,7 +69,7 @@ module.exports = { new CopyWebpackPlugin({ patterns: [ 'test.pdf', - { from: '../node_modules/pdfjs-dist/cmaps/', to: 'cmaps/' }, + { from: cMapsDir, to: 'cmaps/' }, ], }), new HtmlWebpackPlugin({