-
-
Notifications
You must be signed in to change notification settings - Fork 45
feat: add vite-plugin-devtools-json
addon
#581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
manuel3108
merged 19 commits into
sveltejs:main
from
jycouet:addon-vite-plugin-devtools-json
Jun 19, 2025
Merged
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7077835
adding vite-plugin-devtools-json
jycouet de0b781
fix a typo
jycouet b266779
adding a tests
jycouet add2cf9
back to kit
jycouet 0aec23c
check if my tests are affecting the thing ?
jycouet efdfe78
Revert "check if my tests are affecting the thing ?"
jycouet da6972d
also supporting vite project
jycouet 7c20497
Update .changeset/twelve-shirts-tell.md
jycouet aff352e
Update documentation/docs/30-add-ons/60-vite-plugin-devtools-json .md
jycouet 4d326f4
Update packages/addons/vite-plugin-devtools-json/index.ts
jycouet ee436c9
Update packages/addons/vite-plugin-devtools-json/index.ts
jycouet 24ce9b4
update namings
jycouet dec2adb
chromium-devtools -> devtools-json (while waiting for better thing)
jycouet c371572
Update the description of the plugin to help doc search
jycouet d7129ed
using [email protected] to have it working for WSL users
jycouet f00d06f
adding defaultSelection fn in setup phase
jycouet 28eeac7
Merge branch 'main' of github.com:sveltejs/cli into addon-vite-plugin…
jycouet afc01ef
minor tweaks
manuel3108 df9b5ee
ordering
manuel3108 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'sv': patch | ||
--- | ||
|
||
add vite-plugin-devtools-json addon | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
documentation/docs/30-add-ons/60-vite-plugin-devtools-json .md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: vite-plugin-devtools-json | ||
manuel3108 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--- | ||
|
||
[vite-plugin-devtools-json](https://github.com/ChromeDevTools/vite-plugin-devtools-json/) is a Vite plugin for generating the Chrome DevTools project settings file on-the-fly in the devserver. | ||
|
||
## Usage | ||
|
||
```bash | ||
npx sv add vite-plugin-devtools-json | ||
``` | ||
|
||
## What you get | ||
|
||
- the plugin added to your vite plugin options. | ||
jycouet marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { expect } from '@playwright/test'; | ||
import { setupTest } from '../_setup/suite.ts'; | ||
import devtoolsJson from '../../vite-plugin-devtools-json/index.ts'; | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
const { test, variants, prepareServer } = setupTest({ devtoolsJson }); | ||
|
||
test.concurrent.for(variants)('core - %s', async (variant, { page, ...ctx }) => { | ||
const cwd = await ctx.run(variant, { devtoolsJson: {} }); | ||
|
||
const { close } = await prepareServer({ cwd, page }); | ||
// kill server process when we're done | ||
ctx.onTestFinished(async () => await close()); | ||
|
||
const ext = variant.includes('ts') ? 'ts' : 'js'; | ||
const viteFile = path.resolve(cwd, `vite.config.${ext}`); | ||
const viteContent = fs.readFileSync(viteFile, 'utf8'); | ||
|
||
// Check if we have the import part | ||
expect(viteContent).toContain(`import devtoolsJson from`); | ||
expect(viteContent).toContain(`vite-plugin-devtools-json`); | ||
|
||
// Check if it's called | ||
expect(viteContent).toContain(`devtoolsJson()`); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { defineAddon } from '@sveltejs/cli-core'; | ||
import { array, functions, imports, object, exports } from '@sveltejs/cli-core/js'; | ||
import { parseScript } from '@sveltejs/cli-core/parsers'; | ||
|
||
export default defineAddon({ | ||
id: 'vite-plugin-devtools-json', | ||
alias: 'devtools-json', | ||
shortDescription: 'Generate DevTools project settings in the devserver', | ||
jycouet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
homepage: 'https://github.com/ChromeDevTools/vite-plugin-devtools-json', | ||
options: {}, | ||
|
||
run: ({ sv, typescript }) => { | ||
const ext = typescript ? 'ts' : 'js'; | ||
|
||
sv.dependency('vite-plugin-devtools-json', '^0.1.1'); | ||
jycouet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// add the vite plugin | ||
sv.file(`vite.config.${ext}`, (content) => { | ||
const { ast, generateCode } = parseScript(content); | ||
|
||
const vitePluginName = 'devtoolsJson'; | ||
imports.addDefault(ast, 'vite-plugin-devtools-json', vitePluginName); | ||
|
||
const { value: rootObject } = exports.defaultExport(ast, functions.call('defineConfig', [])); | ||
const param1 = functions.argumentByIndex(rootObject, 0, object.createEmpty()); | ||
|
||
const pluginsArray = object.property(param1, 'plugins', array.createEmpty()); | ||
const pluginFunctionCall = functions.call(vitePluginName, []); | ||
array.push(pluginsArray, pluginFunctionCall); | ||
|
||
return generateCode(); | ||
}); | ||
} | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.