feat: add spa integration

This commit is contained in:
Nate Moore 2022-03-26 05:09:19 -05:00 committed by Nate Moore
parent 2615042923
commit 1efab4aa88
4 changed files with 71 additions and 0 deletions

View file

@ -0,0 +1,9 @@
import listen from 'micromorph/spa'
export default () => {
listen({
afterDiff() {
window.dispatchEvent(new CustomEvent('astro:locationchange'))
}
});
}

View 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:*"
}
}

View 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();`);
},
},
};
}

View file

@ -0,0 +1,10 @@
{
"extends": "../../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"allowJs": true,
"module": "ES2020",
"outDir": "./dist",
"target": "ES2020"
}
}