1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Remove __pdfjsdev_webpack__, use webpack options

`__pdfjsdev_webpack__` was used to skip evaluating part of an AST,
in order to not mangle some `require` symbols.
This commit removes `__pdfjsdev_webpack__`, and:

- Uses `__non_webpack_require__` when one wants the output to
  contain `require` instead of `__webpack_require__`.
- Adds options to the webpack config to prevent "polyfills" for
  some Node.js-specific APIs to be added.
- Use `// eslint-disable-next-line no-undef` instead of `/* globals ... */`
  for variables that are not meant to be used globally.
This commit is contained in:
Rob Wu 2017-07-09 15:19:16 +02:00
parent 7b4887dd21
commit 742ed3d1c9
5 changed files with 52 additions and 80 deletions

View file

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals requirejs, __pdfjsdev_webpack__ */
/* globals requirejs, __non_webpack_require__ */
import {
createPromiseCapability, deprecated, getVerbosityLevel, globalScope,
@ -43,21 +43,19 @@ var pdfjsFilePath =
var fakeWorkerFilesLoader = null;
var useRequireEnsure = false;
// The if below protected by __pdfjsdev_webpack__ check from webpack parsing.
if (typeof PDFJSDev !== 'undefined' &&
PDFJSDev.test('GENERIC && !SINGLE_FILE') &&
typeof __pdfjsdev_webpack__ === 'undefined') {
PDFJSDev.test('GENERIC && !SINGLE_FILE')) {
// For GENERIC build we need add support of different fake file loaders
// for different frameworks.
if (typeof window === 'undefined') {
// node.js - disable worker and set require.ensure.
isWorkerDisabled = true;
if (typeof require.ensure === 'undefined') {
require.ensure = require('node-ensure');
if (typeof __non_webpack_require__.ensure === 'undefined') {
__non_webpack_require__.ensure = __non_webpack_require__('node-ensure');
}
useRequireEnsure = true;
} else if (typeof require !== 'undefined' &&
typeof require.ensure === 'function') {
} else if (typeof __non_webpack_require__ !== 'undefined' &&
typeof __non_webpack_require__.ensure === 'function') {
useRequireEnsure = true;
}
if (typeof requirejs !== 'undefined' && requirejs.toUrl) {
@ -66,12 +64,12 @@ if (typeof PDFJSDev !== 'undefined' &&
var dynamicLoaderSupported =
typeof requirejs !== 'undefined' && requirejs.load;
fakeWorkerFilesLoader = useRequireEnsure ? (function (callback) {
require.ensure([], function () {
__non_webpack_require__.ensure([], function () {
var worker;
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('LIB')) {
worker = require('../pdf.worker.js');
worker = __non_webpack_require__('../pdf.worker.js');
} else {
worker = require('./pdf.worker.js');
worker = __non_webpack_require__('./pdf.worker.js');
}
callback(worker.WorkerMessageHandler);
});

View file

@ -12,13 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals global, process, __pdfjsdev_webpack__ */
import './compatibility';
import { ReadableStream } from '../../external/streams/streams-lib';
var globalScope =
(typeof window !== 'undefined' && window.Math === Math) ? window :
// eslint-disable-next-line no-undef
(typeof global !== 'undefined' && global.Math === Math) ? global :
(typeof self !== 'undefined' && self.Math === Math) ? self : this;
@ -1092,11 +1092,8 @@ function isSpace(ch) {
}
function isNodeJS() {
// The if below protected by __pdfjsdev_webpack__ check from webpack parsing.
if (typeof __pdfjsdev_webpack__ === 'undefined') {
return typeof process === 'object' && process + '' === '[object process]';
}
return false;
// eslint-disable-next-line no-undef
return typeof process === 'object' && process + '' === '[object process]';
}
/**