Home / File/ classic-worker.js — vite Source File

classic-worker.js — vite Source File

Architecture documentation for classic-worker.js, a javascript file in the vite codebase.

Entity Profile

Source Code

(() => {})() // this is to test `importScripts` injection doesn't break the code

let base = `/${self.location.pathname.split('/')[1]}`
if (base.endsWith('.js') || base === `/worker-entries`) base = '' // for dev

importScripts(`${base}/classic.js`)

self.addEventListener('message', async (e) => {
  switch (e.data) {
    case 'ping': {
      self.postMessage({
        message: e.data,
        result: self.constant,
      })
      break
    }
    case 'test-import': {
      // Vite may inject imports to handle this dynamic import, make sure
      // it still works in classic workers.
      // NOTE: this test only works in dev.
      const importPath = `${base}/classic-esm.js`
      const { msg } = await import(/* @vite-ignore */ importPath)
      self.postMessage({
        message: e.data,
        result: msg,
      })
      break
    }
  }
})

// for sourcemap
console.log('classic-worker.js')

Frequently Asked Questions

What does classic-worker.js do?
classic-worker.js is a source file in the vite codebase, written in javascript.
Where is classic-worker.js in the architecture?
classic-worker.js is located at playground/worker/classic-worker.js (directory: playground/worker).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free