-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds/modifies examples for node.js and webpack. #6785
Conversation
warn('Setting up fake worker.'); | ||
globalScope.PDFJS.disableWorker = true; | ||
if (!globalScope.PDFJS.disableWorker) { | ||
warn('Setting up fake worker.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making this warning appear only when PDF.js decides to fall back (and not when user explicitly sets the option).
174c5ec
to
0f095a1
Compare
global.DOMParser = require('./domparsermock.js').DOMParserMock; | ||
|
||
require('../../build/singlefile/build/pdf.combined.js'); | ||
// Run `node make dist` to generate 'pdfjs-dist' npm package. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: let's keep this the same as in the other example file and add "files" after "package", i.e., make it "Run node make dist
to generate 'pdfjs-dist' npm package files."
We need to adjust https://github.com/mozilla/pdf.js/wiki/Setup-PDF.js-in-a-website after this lands. We can probably remove the information about webpack and just point to the examples. |
0f095a1
to
79c2f69
Compare
/botio-linux preview |
From: Bot.io (Linux)ReceivedCommand cmd_preview from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/36e378baee529f4/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/36e378baee529f4/output.txt Total script time: 0.81 mins Published |
/botio test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://107.22.172.223:8877/1e10f8a981e3843/output.txt |
From: Bot.io (Linux)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/1a9c9bc2e480cef/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/1e10f8a981e3843/output.txt Total script time: 20.29 mins
|
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/1a9c9bc2e480cef/output.txt Total script time: 20.64 mins
|
Adds/modifies examples for node.js and webpack.
Looks good, thank you! |
This caused a regression.
|
@@ -5,6 +5,7 @@ | |||
"jsdoc": "^3.3.0-alpha9", | |||
"jshint": "~2.8.0", | |||
"wintersmith": "^2.0.0", | |||
"node-ensure": "^0.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is it and why it's needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's needed for webpack to properly split bundles
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the problem is that this is in devDependencies, not runtime dependencies?
@Vanuan Please be more specific. Can you provide examples (preferably online)? |
Previously, pdf-dist worked fine in browser. Now it tries to load non-existing file "node-ensure.js". |
NOTE: This module is not compatible with Browserify. |
@Vanuan there is no support of SystemJS or Browserify for PDF.js yet. (It's coincidence that it worked before) Please file issues and provide short examples -- that will speed up resolution of the issues. Looks like at https://manual-form-digitizing-vanuan.c9users.io/ systemjs was used. For some reason it provides (?) module and module.require object and that confuses our frameworks.js code.
You can skip 'node-ensure' in the Browserify during build step. (We don't have example or docs for that yet) |
Ok, I'll probably submit my own npm module |
It's your choice, but we would prefer that somebody else would add support of those frameworks to the core. Notice that most of PDF.js contributors have no stakes in supporting (integration or testing) other frameworks. |
So, would it be ok to remove node-ensure and replace it with something else? |
Only if will not regress webpack example |
'use strict'; | ||
|
||
var useRequireEnsure = false; | ||
if (typeof module !== 'undefined' && module.require) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about typeof window === 'undefined'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see conflict in node examples we have (due to DOM mock)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeof module !== 'undefined' && module.require
can be changed to something else that will identify only node (preferably in less hacky way)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... maybe it's better to use System.import
polyfill instead of require.ensure
?
https://github.com/ModuleLoader/es6-module-loader
I believe, pdf.js is used more on browser side, so using ES6 modules seems more logical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using require.ensure
is the only way to make it work for webpack, and require.ensure = require('node-ensure) is only way to make it work on node.js as well.
Adding a proper node.js detection (that will not be true for systemjs) will solve your issue
Yes, System.js is a universal loader, so it provides all kinds of loaders, no matter which you choose. Apparently, require.ensure is not among loaders, supported by System.js |
The PDF.js contributors might not be familiar with System.js -- can you create a small example to demonstrate the intended usage? |
See #6791 |
Modifies and cleans up node.js examples to use pdfjs-dist bundle instead of pdf.combined.js
Introduces webpack example to demonstrate proper way to disconnect worker part from display modules. See examples/webpack/README.md for details.