[READ-ONLY] Mirror of https://github.com/danielroe/nuxt-workers. SSR-safe, zero-config Web Workers integration for Nuxt.
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: support scanning works from nuxt layers

resolves https://github.com/danielroe/nuxt-workers/issues/92

+19 -4
+3
playground/app.vue
··· 1 1 <script setup lang="ts"> 2 2 const message = await hi() 3 + const layerMessage = await fromLayer() 3 4 4 5 const clientSideMessage = ref('') 5 6 async function loadClientSideMessage() { ··· 10 11 <template> 11 12 <div> 12 13 {{ message }} 14 + <br> 15 + {{ layerMessage }} 13 16 <br> 14 17 <div> 15 18 {{ clientSideMessage }}
+1
playground/layers/test/nuxt.config.ts
··· 1 + export default defineNuxtConfig({})
+3
playground/layers/test/workers/layer-worker.ts
··· 1 + export function fromLayer() { 2 + return 'Hello from layer worker!' 3 + }
+9 -3
src/module.ts
··· 21 21 name: 'nuxt-workers', 22 22 }, 23 23 defaults: { 24 - dir: '~/workers', 24 + dir: 'workers', 25 25 }, 26 26 async setup(options, nuxt) { 27 27 const scanPattern = nuxt.options.extensions.map(e => `*${e}`) 28 28 29 - const dirs: string[] = [] 29 + const _dirs = new Set<string>() 30 30 for (const dir of Array.isArray(options.dir) ? options.dir : [options.dir]) { 31 - dirs.push(resolve(nuxt.options.srcDir, resolveAlias(dir, nuxt.options.alias))) 31 + for (const layer of nuxt.options._layers) { 32 + _dirs.add(resolve(layer.config.srcDir || layer.cwd, resolveAlias(dir, nuxt.options.alias))) 33 + } 32 34 } 35 + 36 + const dirs = [..._dirs] 37 + 38 + console.log({ dirs }) 33 39 34 40 const context = { 35 41 workerExports: Object.create(null) as Record<string, string>,
+3 -1
test/e2e.spec.ts
··· 10 10 11 11 describe('nuxt-workers', () => { 12 12 it('should work on the server', async () => { 13 - expect(await $fetch('/')).toContain('Hello from worker!') 13 + const html = await $fetch('/') 14 + expect(html).toContain('Hello from worker!') 15 + expect(html).toContain('Hello from layer worker!') 14 16 }) 15 17 16 18 it('should work on the client', async () => {