feat: add spa integration
This commit is contained in:
parent
2615042923
commit
1efab4aa88
4 changed files with 71 additions and 0 deletions
9
packages/integrations/spa/client.js
Normal file
9
packages/integrations/spa/client.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
import listen from 'micromorph/spa'
|
||||
|
||||
export default () => {
|
||||
listen({
|
||||
afterDiff() {
|
||||
window.dispatchEvent(new CustomEvent('astro:locationchange'))
|
||||
}
|
||||
});
|
||||
}
|
37
packages/integrations/spa/package.json
Normal file
37
packages/integrations/spa/package.json
Normal file
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"name": "@astrojs/spa",
|
||||
"description": "SPA Astro Integrations",
|
||||
"version": "0.0.2",
|
||||
"type": "module",
|
||||
"types": "./dist/index.d.ts",
|
||||
"author": "withastro",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/withastro/astro.git",
|
||||
"directory": "packages/integrations/turbolinks"
|
||||
},
|
||||
"keywords": [
|
||||
"astro-component",
|
||||
"performance"
|
||||
],
|
||||
"bugs": "https://github.com/withastro/astro/issues",
|
||||
"homepage": "https://astro.build",
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
"./client.js": "./client.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
||||
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
||||
"dev": "astro-scripts dev \"src/**/*.ts\""
|
||||
},
|
||||
"dependencies": {
|
||||
"micromorph": "^0.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"astro": "workspace:*",
|
||||
"astro-scripts": "workspace:*"
|
||||
}
|
||||
}
|
15
packages/integrations/spa/src/index.ts
Normal file
15
packages/integrations/spa/src/index.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import type { AstroIntegration } from 'astro';
|
||||
|
||||
export default function createPlugin(): AstroIntegration {
|
||||
return {
|
||||
name: '@astrojs/spa',
|
||||
hooks: {
|
||||
'astro:config:setup': ({ injectScript }) => {
|
||||
// This gets injected into the user's page, so we need to re-export Turbolinks
|
||||
// from our own package so that package managers like pnpm don't get mad and
|
||||
// can follow the import correctly.
|
||||
injectScript('page', `import listen from "@astrojs/spa/client.js"; listen();`);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
10
packages/integrations/spa/tsconfig.json
Normal file
10
packages/integrations/spa/tsconfig.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"include": ["src"],
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"module": "ES2020",
|
||||
"outDir": "./dist",
|
||||
"target": "ES2020"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue