Skip to content

Commit

Permalink
feat: module import
Browse files Browse the repository at this point in the history
  • Loading branch information
poyoho committed Mar 10, 2022
1 parent 5870ca2 commit 7a4db00
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/playground/worker/__tests__/worker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test('worker emitted', async () => {
await untilUpdated(() => page.textContent('.nested-worker'), 'pong')
await untilUpdated(
() => page.textContent('.nested-worker-dynamic-import'),
'"msg":"pong"'
'{"msg":"module","msg2":"module2","msg3":"module3"}'
)
})

Expand All @@ -64,7 +64,7 @@ if (isBuild) {
// assert correct files
test('inlined code generation', async () => {
const files = fs.readdirSync(assetsDir)
expect(files.length).toBe(12)
expect(files.length).toBe(14)
const index = files.find((f) => f.includes('index'))
const content = fs.readFileSync(path.resolve(assetsDir, index), 'utf-8')
const worker = files.find((f) => f.includes('my-worker'))
Expand Down
1 change: 1 addition & 0 deletions packages/playground/worker/modules/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const msg = 'module'
2 changes: 2 additions & 0 deletions packages/playground/worker/modules/module2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './module'
export const msg2 = 'module2'
2 changes: 2 additions & 0 deletions packages/playground/worker/modules/module3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './module'
export const msg3 = 'module3'
15 changes: 7 additions & 8 deletions packages/playground/worker/sub-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ self.onmessage = (event) => {
self.postMessage('pong')
}
}
const data = import('./workerImport')
data.then((data) => {
const { mode, msg } = data
self.postMessage({
mode,
msg
})
})

Promise.all([import('./modules/module2'), import('./modules/module3')]).then(
(data) => {
const _data = { ...data[0], ...data[1] }
self.postMessage(_data)
}
)

0 comments on commit 7a4db00

Please sign in to comment.