فهرست منبع

Set `workerPublicPath` in webpack config (#20629)

GitOrigin-RevId: 3fba33a6b52bf2a91f3126efc9d76f6f1dfbc1c4
Alf Eaton 1 سال پیش
والد
کامیت
53d6b4dfd0

+ 3 - 0
services/web/cypress/support/webpack.cypress.ts

@@ -6,6 +6,9 @@ import devConfig from '../../webpack.config.dev'
 
 const buildConfig = () => {
   const webpackConfig = merge(devConfig, {
+    output: {
+      workerPublicPath: '/__cypress/src/',
+    },
     devServer: {
       static: path.join(__dirname, '../../public'),
       port: 3200,

+ 4 - 6
services/web/frontend/js/features/pdf-preview/util/pdf-js.ts

@@ -1,14 +1,12 @@
-import { createWorker } from '@/utils/worker'
 import * as PDFJS from 'pdfjs-dist'
 import type { DocumentInitParameters } from 'pdfjs-dist/types/src/display/api'
 
 export { PDFJS }
 
-createWorker(() => {
-  PDFJS.GlobalWorkerOptions.workerPort = new Worker(
-    new URL('pdfjs-dist/build/pdf.worker.mjs', import.meta.url) // NOTE: .mjs extension
-  )
-})
+PDFJS.GlobalWorkerOptions.workerPort = new Worker(
+  /* webpackChunkName: "pdf-worker" */
+  new URL('pdfjs-dist/build/pdf.worker.mjs', import.meta.url) // NOTE: .mjs extension
+)
 
 export const imageResourcesPath = '/images/pdfjs-dist/'
 const cMapUrl = '/js/pdfjs-dist/cmaps/'

+ 6 - 8
services/web/frontend/js/features/source-editor/hunspell/HunspellManager.ts

@@ -1,5 +1,4 @@
 import { v4 as uuid } from 'uuid'
-import { createWorker } from '@/utils/worker'
 import getMeta from '@/utils/meta'
 import { debugConsole } from '@/utils/debugging'
 
@@ -50,14 +49,13 @@ export class HunspellManager {
 
     this.dictionariesRoot = getMeta('ol-dictionariesRoot')
 
-    createWorker(() => {
-      this.hunspellWorker = new Worker(
-        new URL('./hunspell.worker.ts', import.meta.url),
-        { type: 'module' }
-      )
+    this.hunspellWorker = new Worker(
+      /* webpackChunkName: "hunspell-worker" */
+      new URL('./hunspell.worker.ts', import.meta.url),
+      { type: 'module' }
+    )
 
-      this.hunspellWorker.addEventListener('message', this.receive.bind(this))
-    })
+    this.hunspellWorker.addEventListener('message', this.receive.bind(this))
   }
 
   destroy() {

+ 5 - 8
services/web/frontend/js/features/source-editor/languages/latex/linter/latex-linter.ts

@@ -1,16 +1,13 @@
-import { createWorker } from '../../../../../utils/worker'
 import { EditorView } from '@codemirror/view'
 import { Diagnostic } from '@codemirror/lint'
 import { errorsToDiagnostics, LintError } from './errors-to-diagnostics'
 import { mergeCompatibleOverlappingDiagnostics } from './merge-overlapping-diagnostics'
 
-let lintWorker: Worker
-createWorker(() => {
-  lintWorker = new Worker(
-    new URL('./latex-linter.worker.js', import.meta.url),
-    { type: 'module' }
-  )
-})
+const lintWorker = new Worker(
+  /* webpackChunkName: "latex-linter-worker" */
+  new URL('./latex-linter.worker.js', import.meta.url),
+  { type: 'module' }
+)
 
 class Deferred {
   public promise: Promise<readonly Diagnostic[]>

+ 0 - 9
services/web/frontend/js/utils/worker.js

@@ -1,9 +0,0 @@
-export const createWorker = callback => {
-  if (process.env.CYPRESS) {
-    return callback()
-  }
-  const webpackPublicPath = __webpack_public_path__
-  __webpack_public_path__ = '/'
-  callback()
-  __webpack_public_path__ = webpackPublicPath
-}

+ 1 - 0
services/web/webpack.config.js

@@ -98,6 +98,7 @@ module.exports = {
     path: path.join(__dirname, 'public'),
 
     publicPath: '/',
+    workerPublicPath: '/',
 
     // By default write into js directory
     filename: 'js/[name]-[contenthash].js',