Skip to content

Commit

Permalink
Update example to Vite v5
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkleemans committed Nov 17, 2023
1 parent 9d8a536 commit 03803ad
Show file tree
Hide file tree
Showing 26 changed files with 1,436 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yml
Expand Up @@ -11,7 +11,7 @@ jobs:
uses: cypress-io/github-action@v4
with:
build: npm run example:build
start: npm run example:serve
wait-on: http://localhost:5000
start: npm run example:preview
wait-on: http://localhost:4173
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
5 changes: 2 additions & 3 deletions README.md
Expand Up @@ -92,10 +92,9 @@ import IconWithoutOptimizer from './my-icon.svg?skipsvgo'
```

### Use with TypeScript
If you use the loader in a Typescript project, you'll need to import your svg files with the `?component` param: `import MyIcon from './my-icon.svg?component'`.

You'll also need to reference the type definitions:
If you use the loader in a Typescript project, you'll need to reference the type definitions inside `vite-env.d.ts`:
```ts
/// <reference types="vite/client" />
/// <reference types="vite-svg-loader" />
```

Expand Down
3 changes: 2 additions & 1 deletion cypress.json
@@ -1,4 +1,5 @@
{
"baseUrl": "http://localhost:5000",
"baseUrl": "http://localhost:4173",
"screenshotOnRunFailure": false,
"video": false
}
5 changes: 0 additions & 5 deletions cypress/fixtures/example.json

This file was deleted.

2 changes: 1 addition & 1 deletion cypress/integration/spec.js
Expand Up @@ -42,7 +42,7 @@ describe('Vite SVG Loader', () => {
})

it('supports ?url param', () => {
cy.get('#url').contains(/^\/assets\/test\..+\.svg/)
cy.get('#url').contains(/^data:image\/svg\+xml/)
})

it('supports ?raw param', () => {
Expand Down
24 changes: 24 additions & 0 deletions example/.gitignore
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 3 additions & 0 deletions example/.vscode/extensions.json
@@ -0,0 +1,3 @@
{
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
}
18 changes: 18 additions & 0 deletions example/README.md
@@ -0,0 +1,18 @@
# Vue 3 + TypeScript + Vite

This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

## Recommended IDE Setup

- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

## Type Support For `.vue` Imports in TS

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:

1. Disable the built-in TypeScript Extension
1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2. Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
13 changes: 13 additions & 0 deletions example/index.html
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

0 comments on commit 03803ad

Please sign in to comment.