Skip to content

Commit

Permalink
Use file-loader, not worker-loader, for default Webpack entry (#756)
Browse files Browse the repository at this point in the history
In test directory:
Before: 3 729 618 B, 19500 ms compilation time
After: 3 729 459, 11200 ms compilation time
  • Loading branch information
wojtekmaj authored Apr 1, 2021
1 parent d76ae11 commit ea0daa9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 50 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.0.0",
"file-loader": "^6.0.0",
"make-cancellable-promise": "^1.0.0",
"make-event-props": "^1.1.0",
"merge-class-names": "^1.1.1",
"merge-refs": "^1.0.0",
"pdfjs-dist": "2.6.347",
"prop-types": "^15.6.2",
"worker-loader": "^3.0.0"
"prop-types": "^15.6.2"
},
"devDependencies": {
"@babel/cli": "^7.8.0",
Expand Down
8 changes: 3 additions & 5 deletions src/entry.webpack.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import * as pdfjs from 'pdfjs-dist';
// eslint-disable-next-line
import pdfjsWorker from 'file-loader!pdfjs-dist/build/pdf.worker';

import Document from './Document';
import Outline from './Outline';
import Page from './Page';
// eslint-disable-next-line
import PdfjsWorker from 'worker-loader!./pdf.worker.entry.js';

import { isLocalFileSystem, warnOnDev } from './shared/utils';

if (isLocalFileSystem) {
warnOnDev('You are running React-PDF from your local file system. PDF.js Worker may fail to load due to browser\'s security policies. If you\'re on Google Chrome, you can use --allow-file-access-from-files flag for debugging purposes.');
}

if (typeof window !== 'undefined' && 'Worker' in window) {
pdfjs.GlobalWorkerOptions.workerPort = new PdfjsWorker();
}
pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;

export {
pdfjs,
Expand Down
4 changes: 2 additions & 2 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"babel-loader": "^8.0.0",
"copy-webpack-plugin": "^8.0.0",
"css-loader": "^4.3.0",
"file-loader": "^6.0.0",
"html-webpack-plugin": "^5.1.0",
"less": "^4.0.0",
"less-loader": "^8.0.0",
Expand All @@ -36,8 +37,7 @@
"style-loader": "^1.2.0",
"webpack": "^5.20.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0",
"worker-loader": "^3.0.0"
"webpack-dev-server": "^3.11.0"
},
"resolutions": {
"rimraf@2.6.3": "^2.6.3",
Expand Down
2 changes: 1 addition & 1 deletion test/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
},
resolveLoader: {
alias: {
'worker-loader': require.resolve('worker-loader'),
'file-loader': require.resolve('file-loader'),
},
},
module: {
Expand Down
30 changes: 15 additions & 15 deletions test/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4671,6 +4671,18 @@ __metadata:
languageName: node
linkType: hard

"file-loader@npm:^6.0.0":
version: 6.2.0
resolution: "file-loader@npm:6.2.0"
dependencies:
loader-utils: ^2.0.0
schema-utils: ^3.0.0
peerDependencies:
webpack: ^4.0.0 || ^5.0.0
checksum: 0f103418c072ec66c081a9908cd7824ee19905e18be16889cb050f5f373998afaf7ca4c2fd2df4cabf703a2cd526aefe59105930e3f8d266a5b35e6d5f5b3cf4
languageName: node
linkType: hard

"file-uri-to-path@npm:1.0.0":
version: 1.0.0
resolution: "file-uri-to-path@npm:1.0.0"
Expand Down Expand Up @@ -8590,6 +8602,7 @@ fsevents@^2.1.2:
babel-loader: ^8.0.0
copy-webpack-plugin: ^8.0.0
css-loader: ^4.3.0
file-loader: ^6.0.0
html-webpack-plugin: ^5.1.0
less: ^4.0.0
less-loader: ^8.0.0
Expand All @@ -8603,7 +8616,6 @@ fsevents@^2.1.2:
webpack: ^5.20.0
webpack-cli: ^4.2.0
webpack-dev-server: ^3.11.0
worker-loader: ^3.0.0
languageName: unknown
linkType: soft

Expand All @@ -8623,6 +8635,7 @@ fsevents@^2.1.2:
enzyme: ^3.10.0
eslint: ^7.12.0
eslint-config-wojtekmaj: ^0.5.0
file-loader: ^6.0.0
jest: ^26.6.0
make-cancellable-promise: ^1.0.0
make-event-props: ^1.1.0
Expand All @@ -8634,7 +8647,6 @@ fsevents@^2.1.2:
react-dom: ^17.0.0
rimraf: ^3.0.0
webpack: ^5.20.0
worker-loader: ^3.0.0
peerDependencies:
react: ^16.3.0 || ^17.0.0-0
react-dom: ^16.3.0 || ^17.0.0-0
Expand Down Expand Up @@ -9215,7 +9227,7 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"schema-utils@npm:^2.6.5, schema-utils@npm:^2.6.6, schema-utils@npm:^2.7.0, schema-utils@npm:^2.7.1":
"schema-utils@npm:^2.6.5, schema-utils@npm:^2.6.6, schema-utils@npm:^2.7.1":
version: 2.7.1
resolution: "schema-utils@npm:2.7.1"
dependencies:
Expand Down Expand Up @@ -10865,18 +10877,6 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"worker-loader@npm:^3.0.0":
version: 3.0.2
resolution: "worker-loader@npm:3.0.2"
dependencies:
loader-utils: ^2.0.0
schema-utils: ^2.7.0
peerDependencies:
webpack: ^4.0.0 || ^5.0.0
checksum: 3e4a8f31f42435e6bfd15d5bc61fab32461328b67391d8f83f0332b7b338e001c9f52d23f095a01299c20f6d00c4ae9a6319edbf993964415e2cdc5813148dfd
languageName: node
linkType: hard

"wrap-ansi@npm:^5.1.0":
version: 5.1.0
resolution: "wrap-ansi@npm:5.1.0"
Expand Down
39 changes: 14 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ __metadata:
languageName: node
linkType: hard

"@types/json-schema@npm:*, @types/json-schema@npm:^7.0.5, @types/json-schema@npm:^7.0.6":
"@types/json-schema@npm:*, @types/json-schema@npm:^7.0.6":
version: 7.0.6
resolution: "@types/json-schema@npm:7.0.6"
checksum: 820cabe35ac915b93e38b0c01957e5c49d7d9f69251dddfbf39af0ff4fe24f6e08b39e55603e0d212dea7bcaa383b1218b58a738d1c02013dc22df06547ff238
Expand Down Expand Up @@ -3954,6 +3954,18 @@ __metadata:
languageName: node
linkType: hard

"file-loader@npm:^6.0.0":
version: 6.2.0
resolution: "file-loader@npm:6.2.0"
dependencies:
loader-utils: ^2.0.0
schema-utils: ^3.0.0
peerDependencies:
webpack: ^4.0.0 || ^5.0.0
checksum: 0f103418c072ec66c081a9908cd7824ee19905e18be16889cb050f5f373998afaf7ca4c2fd2df4cabf703a2cd526aefe59105930e3f8d266a5b35e6d5f5b3cf4
languageName: node
linkType: hard

"file-uri-to-path@npm:1.0.0":
version: 1.0.0
resolution: "file-uri-to-path@npm:1.0.0"
Expand Down Expand Up @@ -6941,6 +6953,7 @@ fsevents@^2.1.2:
enzyme: ^3.10.0
eslint: ^7.12.0
eslint-config-wojtekmaj: ^0.5.0
file-loader: ^6.0.0
jest: ^26.6.0
make-cancellable-promise: ^1.0.0
make-event-props: ^1.1.0
Expand All @@ -6952,7 +6965,6 @@ fsevents@^2.1.2:
react-dom: ^17.0.0
rimraf: ^3.0.0
webpack: ^5.20.0
worker-loader: ^3.0.0
peerDependencies:
react: ^16.3.0 || ^17.0.0-0
react-dom: ^16.3.0 || ^17.0.0-0
Expand Down Expand Up @@ -7426,17 +7438,6 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"schema-utils@npm:^2.7.0":
version: 2.7.1
resolution: "schema-utils@npm:2.7.1"
dependencies:
"@types/json-schema": ^7.0.5
ajv: ^6.12.4
ajv-keywords: ^3.5.2
checksum: 3851bcc7e44a3f35d3ca96e460c598aa24cec9fe395b196395316a043dc111d25735a9a49b1a115e4b52d5ed0d8bbcfb9fe1bfd077610f192b613e020d3f3ef2
languageName: node
linkType: hard

"schema-utils@npm:^3.0.0":
version: 3.0.0
resolution: "schema-utils@npm:3.0.0"
Expand Down Expand Up @@ -8621,18 +8622,6 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"worker-loader@npm:^3.0.0":
version: 3.0.1
resolution: "worker-loader@npm:3.0.1"
dependencies:
loader-utils: ^2.0.0
schema-utils: ^2.7.0
peerDependencies:
webpack: ^4.0.0 || ^5.0.0
checksum: 4b8f557744da545cdc0d510ccab90ee68ba98516dd402b1e547e01011489d35b45909c35c686c9d7be8002ccd873abfc88a50ab2336cf94eca672a7daeba0bc1
languageName: node
linkType: hard

"wrap-ansi@npm:^6.2.0":
version: 6.2.0
resolution: "wrap-ansi@npm:6.2.0"
Expand Down

0 comments on commit ea0daa9

Please sign in to comment.