mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 10:38:16 +08:00
feat: pdf worker js 打包调整
This commit is contained in:
parent
dcac3de529
commit
8b29fdd65b
@ -4,7 +4,7 @@ import {createRoot} from 'react-dom/client';
|
||||
import axios from 'axios';
|
||||
import {match} from 'path-to-regexp';
|
||||
import copy from 'copy-to-clipboard';
|
||||
import {normalizeLink} from 'amis-core';
|
||||
import {normalizeLink, supportsMjs} from 'amis-core';
|
||||
|
||||
import qs from 'qs';
|
||||
import {
|
||||
@ -20,6 +20,7 @@ import {
|
||||
import 'amis-ui/lib/locale/en-US';
|
||||
import 'history';
|
||||
import {attachmentAdpator} from 'amis-core';
|
||||
import {pdfUrlLoad} from './loadPdfjsWorker';
|
||||
|
||||
import type {ToastLevel, ToastConf} from 'amis-ui/lib/components/Toast';
|
||||
|
||||
@ -249,7 +250,7 @@ export function embed(
|
||||
richTextToken: '',
|
||||
affixOffsetBottom: 0,
|
||||
customStyleClassPrefix: '.amis-scope',
|
||||
pdfjsWorkerSrc: '/sdk/thirds/pdfjs-dist/build/pdf.worker.min.mjs',
|
||||
pdfjsWorkerSrc: supportsMjs() ? pdfUrlLoad() : '',
|
||||
...env
|
||||
};
|
||||
|
||||
|
17
examples/loadPdfjsWorker.ts
Normal file
17
examples/loadPdfjsWorker.ts
Normal file
@ -0,0 +1,17 @@
|
||||
// 这是个特殊的方法,请看考 mod.js 里面的实现。
|
||||
export function pdfUrlLoad() {
|
||||
// @ts-ignore
|
||||
const pdfWorker = __uri('pdfjs-dist/build/pdf.worker.min.mjs');
|
||||
|
||||
return filterUrl(pdfWorker);
|
||||
}
|
||||
|
||||
function __uri(url: string) {
|
||||
return url;
|
||||
}
|
||||
|
||||
// 用于发布 sdk 版本的时候替换,因为不确定 sdk 版本怎么部署,而 worker 地址路径不可知。
|
||||
// 所以会被 fis3 替换成取相对的代码。
|
||||
function filterUrl(url: string) {
|
||||
return url;
|
||||
}
|
@ -650,7 +650,8 @@ if (fis.project.currentMedia() === 'publish-sdk') {
|
||||
// 如果 sdk 和 worker 不是部署在一个地方,请通过指定 MonacoEnvironment.getWorkerUrl
|
||||
if (
|
||||
file.subpath === '/node_modules/amis-ui/lib/components/Editor.js' ||
|
||||
file.subpath === '/examples/loadMonacoEditor.ts'
|
||||
file.subpath === '/examples/loadMonacoEditor.ts' ||
|
||||
file.subpath === '/examples/loadPdfjsWorker.ts'
|
||||
) {
|
||||
contents = contents.replace(
|
||||
/function\sfilterUrl\(url\)\s\{\s*return\s*url;/m,
|
||||
|
@ -2329,3 +2329,12 @@ export class TestIdBuilder {
|
||||
return data ? filter(this.testId, data) : this.testId;
|
||||
}
|
||||
}
|
||||
|
||||
export function supportsMjs() {
|
||||
try {
|
||||
new Function('import("")');
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user