在一个缩小的JS文件中包含pdf.worker.js

时间:2017-03-22 06:37:45

标签: gruntjs minify pdfjs

PDF.js需要名为pdf.worker.js的文件。如果您将PDF.js包含在HTML中,那就没关系<?php require_once '../includes/DbOperations.php'; $response = array(); if($_SERVER['REQUEST_METHOD']=='POST') { if( isset($_POST['cname']) and isset($_POST['date']) and isset($_POST['lname']) and isset($_POST['fname']) and isset($_POST['mi']) and isset($_POST['email']) and isset($_POST['country']) and isset($_POST['city']) and isset($_POST['tbuyer'])) { //operate the data further $db = new DbOperations(); if($db->registerBuyer( $_POST['cname'], $_POST['date'], $_POST['lname'], $_POST['fname'], $_POST['mi'], $_POST['email'], $_POST['country'], $_POST['city'], $_POST['tbuyer'] )) { $response['error'] = false; $response['message'] = "Buyer Registered Successfully"; } else { $response['error'] = true; $response['message'] = "Some error occured try again"; } } else { $response['error'] = true; $response['message'] = "Required fields are missing"; } } else { $response['error'] = true; $response['message'] ="Invalid request"; } echo json_encode($response); ?> PDF.js将查找存储pdf.js的位置(在我的例子中,<script type="text/javascript" src="plugins/pdfjs-dist/build/pdf.js"></script>)作为其工作文件。但是,就我而言,我想将所有JavaScript依赖项连接并缩小为一个文件。 (通过Grunt。)

我如何为pdf.worker.js文件执行此操作?如何将它包含在我的唯一JS文件中?

所以,我在Grunt所做的就是

plugins/pdfjs-dist/build/

这是有效的,但它远非优雅的解决方案。除了看起来丑陋以及附加文件的必要性之外,很有可能有人将copy: { build: { files: [ { src: 'src/plugins/pdfjs-dist/build/pdf.worker.js', dest: 'dist/name_of_my_app.worker.js' } ] } } 重命名为其他内容,忽略了复制过程,从而破坏了PDF.js

0 个答案:

没有答案