-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
3,404 additions
and
3,349 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
--- | ||
"@crxjs/vite-plugin": patch | ||
--- | ||
|
||
Proxy Cache-Control header |
This file contains 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 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 @@ | ||
--- | ||
'@crxjs/vite-plugin': major | ||
--- | ||
|
||
fix: workaround for the issue with chrome.runtime.getURL introduced in Chrome 130 causing CSP rejecting script due to different origin (GUID instead of chrome extension id) |
This file contains 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,6 @@ | ||
--- | ||
"@crxjs/vite-plugin": patch | ||
--- | ||
|
||
build(deps): bump rollup from 2.78.1 to 2.79.2 in /packages/vite-plugin | ||
build(deps): bump vite from 3.1.7 to 3.2.11 in /packages/vite-plugin |
This file contains 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 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
116 changes: 116 additions & 0 deletions
116
packages/vite-plugin-docs/docs/common/ImageCodeBlock.js
This file contains 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,116 @@ | ||
import React from 'react'; | ||
import CodeBlock from '@theme/CodeBlock'; | ||
|
||
// Helper function to dedent the code | ||
const dedent = (str) => { | ||
const lines = str.split('\n'); | ||
const minIndent = Math.min( | ||
...lines.filter(line => line.trim()).map(line => line.match(/^ */)[0].length) | ||
); | ||
return lines.map(line => line.slice(minIndent)).join('\n').trim(); | ||
}; | ||
|
||
const reactCodeBlock = () => { | ||
return ( | ||
<div> | ||
<CodeBlock | ||
language='jsx' | ||
title='App.jsx'> | ||
{dedent(` | ||
<img | ||
// highlight-next-line | ||
src={chrome.runtime.getURL('icons/logo.png')} | ||
className='App-logo' | ||
alt='logo' | ||
/> | ||
`)} | ||
</CodeBlock> | ||
</div> | ||
) | ||
}; | ||
|
||
const solidCodeBlock = () => { | ||
return ( | ||
<div> | ||
<CodeBlock | ||
language='jsx' | ||
title='App.jsx'> | ||
{dedent(` | ||
<img | ||
// highlight-next-line | ||
src={chrome.runtime.getURL('icons/logo.png')} | ||
className='App-logo' | ||
alt='logo' | ||
/> | ||
`)} | ||
</CodeBlock> | ||
</div> | ||
) | ||
} | ||
|
||
const vanillaCodeBlock = () => { | ||
return ( | ||
<div> | ||
<CodeBlock | ||
language='jsx' | ||
title='App.jsx'> | ||
{dedent(` | ||
<img | ||
// highlight-next-line | ||
src={chrome.runtime.getURL('icons/logo.png')} | ||
className='App-logo' | ||
alt='logo' | ||
/> | ||
`)} | ||
</CodeBlock> | ||
</div> | ||
) | ||
} | ||
|
||
const vueCodeBlock = () => { | ||
return ( | ||
<div> | ||
<CodeBlock | ||
language='jsx' | ||
title='App.vue'> | ||
{dedent(` | ||
<script setup> | ||
import logo from './assets/image.png'; | ||
// highlight-next-line | ||
const logoUrl = chrome.runtime.getURL(logo); | ||
</script> | ||
<template> | ||
<img :src="logoUrl" className='App-logo' alt='logo' /> | ||
</template> | ||
`)} | ||
</CodeBlock> | ||
</div> | ||
) | ||
} | ||
|
||
const factory = (framework) => { | ||
switch (framework) { | ||
case 'react': | ||
return reactCodeBlock(); | ||
case 'solid': | ||
return solidCodeBlock(); | ||
case 'vanilla': | ||
return vanillaCodeBlock(); | ||
case 'vue': | ||
return vueCodeBlock(); | ||
default: | ||
return "No code block available"; | ||
} | ||
}; | ||
|
||
const ImageCodeBlock = ({ framework }) => { | ||
const codeBlock = factory(framework); | ||
return ( | ||
<div> | ||
{codeBlock} | ||
</div> | ||
); | ||
}; | ||
|
||
export { ImageCodeBlock }; |
31 changes: 31 additions & 0 deletions
31
packages/vite-plugin-docs/docs/common/_get-url-for-images.mdx
This file contains 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,31 @@ | ||
import { ImageCodeBlock } from './ImageCodeBlock'; | ||
|
||
## Get the right URL | ||
|
||
:::info | ||
|
||
<!-- Add link to Chrome Dev Docs --> | ||
|
||
Content scripts share the origin of the page where they run. | ||
|
||
::: | ||
|
||
The browser treats the imported value `logo` as a URL from the host page. If the | ||
content script is running on `https://google.com`, the `img` tag will | ||
try to load from `https://google.com/logo.svg`. | ||
|
||
Images first must be specified in the `web_accessible_resources` field in your `manifest.json` file: | ||
|
||
|
||
```json title="manifest.json" | ||
"web_accessible_resources": [ | ||
{ | ||
"resources": [ "icons/*.png"], | ||
"matches": [] | ||
} | ||
] | ||
``` | ||
|
||
Then you reference the image in your content script using the [chrome.runtime.getURL](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/getURL) method: | ||
|
||
<ImageCodeBlock framework={props.framework} /> |
83 changes: 26 additions & 57 deletions
83
packages/vite-plugin-docs/docs/getting-started/_create-project-tabs.mdx
This file contains 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 |
---|---|---|
@@ -1,57 +1,26 @@ | ||
import Tabs from '@theme/Tabs' | ||
import TabItem from '@theme/TabItem' | ||
|
||
## Create a project | ||
|
||
Use your favorite package manager to scaffold a new project and follow the | ||
prompts to create a vanilla JS project. | ||
|
||
<Tabs groupId='vite-version'> | ||
<TabItem value='vite2' label='Vite 2' default> | ||
|
||
```sh | ||
npm init vite@^2.9.4 | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value='vite3' label='Vite 3 (beta)'> | ||
|
||
```sh | ||
npm init vite@latest | ||
``` | ||
|
||
:::info beta | ||
|
||
CRXJS support for Vite 3 is in beta. | ||
|
||
::: | ||
|
||
:::info react users | ||
|
||
HMR in CRXJS is incompatible with `@vite/plugin-react-swc`. We recommend using @vitejs/plugin-react instead. | ||
|
||
::: | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
## Install CRXJS Vite plugin | ||
|
||
Now install the CRXJS Vite plugin using your favorite package manager. | ||
|
||
<Tabs groupId='vite-version'> | ||
<TabItem value='vite2' label='Vite 2' default> | ||
|
||
```sh | ||
npm i @crxjs/vite-plugin@latest -D | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value='vite3' label='Vite 3 (beta)'> | ||
|
||
```sh | ||
npm i @crxjs/vite-plugin@beta -D | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
import Admonition from '@theme/Admonition'; | ||
|
||
export const CreateProjectTabs = ({ projectType }) => | ||
<> | ||
<p>Use your favorite package manager to scaffold a new project and follow the prompts to create a {projectType} project.</p> | ||
<Tabs groupId='vite-version'> | ||
<TabItem value='vite2' label='Vite 2' default> | ||
<pre> | ||
<code>npm init vite@^2.9.4</code> | ||
</pre> | ||
</TabItem> | ||
<TabItem value='vite3' label='Vite 3 (beta)'> | ||
<pre> | ||
<code>npm init vite@latest</code> | ||
</pre> | ||
<Admonition type="info" title="beta"> | ||
CRXJS support for Vite 3 is in beta. | ||
</Admonition> | ||
<Admonition type="info" title="React Users"> | ||
HMR in CRXJS is incompatible with <code>@vite/plugin-react-swc</code>. We recommend using <code>@vitejs/plugin-react</code> instead. | ||
</Admonition> | ||
</TabItem> | ||
</Tabs> | ||
</> |
This file contains 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 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
Oops, something went wrong.