Skip to content

Commit 1c64a6e

Browse files
committed
test(amd): add amd playground
1 parent 806edb7 commit 1c64a6e

File tree

8 files changed

+78
-0
lines changed

8 files changed

+78
-0
lines changed

playground/amd/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# amd

playground/amd/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>amd</title>
6+
</head>
7+
<body>
8+
<script src="node_modules/requirejs/require.js"></script>
9+
<script type="text/javascript">
10+
requirejs(
11+
['plugin/dist/js/plugin.js'],
12+
(plugin) => {
13+
console.log('Plugin loaded', plugin())
14+
},
15+
(err) => {
16+
console.error('Error loading plugin', err)
17+
},
18+
)
19+
</script>
20+
</body>
21+
</html>

playground/amd/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"scripts": {
3+
"build": "pnpm run -r build"
4+
},
5+
"dependencies": {
6+
"requirejs": "^2.3.7"
7+
}
8+
}

playground/amd/plugin/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<html />

playground/amd/plugin/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import workerUrl from './worker?url&no-inline'
2+
3+
export default function pluginMain() {
4+
console.log('workerUrl', workerUrl)
5+
return 'OK'
6+
}

playground/amd/plugin/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"scripts": {
3+
"build": "vite build"
4+
}
5+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { join } from 'node:path'
2+
import { defineConfig } from 'vite'
3+
4+
export default defineConfig((config) => {
5+
const isProduction = false // config.mode === 'production'
6+
return {
7+
base: './',
8+
build: {
9+
outDir: './dist',
10+
minify: isProduction,
11+
rollupOptions: {
12+
preserveEntrySignatures: 'strict',
13+
input: {
14+
plugin: './index.ts',
15+
},
16+
output: {
17+
format: 'amd',
18+
assetFileNames: join(
19+
'assets',
20+
`[name]${isProduction ? '-[hash]' : ''}[extname]`,
21+
),
22+
chunkFileNames: join(
23+
'js',
24+
'chunks',
25+
`[name]${isProduction ? '-[hash]' : ''}.mjs`,
26+
),
27+
entryFileNames: join(
28+
'js',
29+
`[name]${isProduction ? '-[hash]' : ''}.js`,
30+
),
31+
},
32+
},
33+
},
34+
}
35+
})

playground/amd/plugin/worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("I'm a worker")

0 commit comments

Comments
 (0)