Skip to content

Commit 7ff490d

Browse files
committed
Add content-svgr template
1 parent dc1b506 commit 7ff490d

22 files changed

+310
-24
lines changed

examples/content-extension-config/package.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@
1414
"email": "[email protected]",
1515
"url": "https://cezaraugusto.com"
1616
},
17-
"files": [
18-
"template",
19-
"template.json"
20-
],
21-
"keywords": [
22-
"extension",
23-
"browser-extension",
24-
"web-extension",
25-
"template"
26-
],
2717
"dependencies": {
2818
"@svgr/webpack": "^8.1.0",
2919
"react": "^18.1.0",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
6+
# testing
7+
coverage
8+
9+
# production
10+
dist
11+
12+
# misc
13+
.DS_Store
14+
15+
# local env files
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
# lock files
22+
yarn.lock
23+
package-lock.json
24+
25+
# debug files
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
30+
# extension.js
31+
extension-env.d.ts
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('Hello from the background script!')
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import React from 'react'
2+
import ReactLogo from '../images/logo.svg'
3+
import tailwindBg from '../images/tailwind_bg.png'
4+
import typescriptLogo from '../images/typescript.png'
5+
import tailwindLogo from '../images/tailwind.png'
6+
import chromeWindowBg from '../images/chromeWindow.png'
7+
8+
export default function ContentApp() {
9+
const [isdialogOpen, setIsDialogOpen] = React.useState(true)
10+
11+
if (!isdialogOpen) {
12+
return (
13+
<div className="mx-auto p-6">
14+
<button
15+
onClick={() => setIsDialogOpen(true)}
16+
className="bg-white rounded-md p-3 text-sm font-semibold text-gray-900 shadow-sm hover:bg-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
17+
>
18+
🧩 Open content script hint <span aria-hidden="true">+</span>
19+
</button>
20+
</div>
21+
)
22+
}
23+
24+
return (
25+
<div className="mx-auto max-w-7xl md:px-0 lg:p-6">
26+
<div className="relative isolate overflow-hidden bg-gray-900 px-6 pt-16 shadow-2xl lg:rounded-3xl md:pt-24 md:h-full sm:h-[100vh] lg:flex lg:gap-x-20 lg:px-24 lg:pt-0">
27+
<div className="absolute z-20 top-0 inset-x-0 flex justify-center overflow-hidden pointer-events-none">
28+
<div className="w-[108rem] flex-none flex justify-end">
29+
<picture>
30+
<img
31+
src={tailwindBg}
32+
alt=""
33+
className="w-[90rem] flex-none max-w-none hidden dark:block"
34+
decoding="async"
35+
/>
36+
</picture>
37+
</div>
38+
</div>
39+
<div className="mx-auto max-w-md text-center lg:py-12 lg:mx-0 lg:flex-auto lg:text-left">
40+
<div className="flex items-center justify-center space-x-4 my-4 mx-auto">
41+
<ReactLogo className="relative inline-block w-12" />
42+
<div className="text-3xl text-white">+</div>
43+
<img
44+
alt="TypeScript logo"
45+
src={typescriptLogo}
46+
className="relative inline-block w-12"
47+
/>
48+
<div className="text-3xl text-white">+</div>
49+
<img
50+
alt="Tailwind logo"
51+
src={tailwindLogo}
52+
className="relative inline-block w-12"
53+
/>
54+
</div>
55+
<h2 className="text-3xl font-bold tracking-tight text-white sm:text-4xl">
56+
This is a content script running React, TypeScript, and Tailwind.css
57+
</h2>
58+
<p className="mt-6 text-lg leading-8 text-gray-300">
59+
Learn more about creating cross-browser extensions by{' '}
60+
<button
61+
onClick={() => setIsDialogOpen(false)}
62+
className="underline hover:no-underline
63+
"
64+
>
65+
closing this hint
66+
</button>
67+
.
68+
</p>
69+
</div>
70+
<div className="relative mt-16 h-80 lg:mt-8">
71+
<img
72+
className="absolute left-0 top-0 w-[57rem] max-w-none rounded-md bg-white/5 ring-1 ring-white/10"
73+
src={chromeWindowBg}
74+
alt="Chrome window screenshot"
75+
width="1824"
76+
height="1080"
77+
/>
78+
</div>
79+
</div>
80+
</div>
81+
)
82+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import ReactDOM from 'react-dom/client'
2+
import ContentApp from './ContentApp'
3+
import './styles.css'
4+
5+
setTimeout(initial, 1000)
6+
7+
function initial() {
8+
// Create a new div element and append it to the document's body
9+
const rootDiv = document.createElement('div')
10+
rootDiv.id = 'extension-root'
11+
document.body.appendChild(rootDiv)
12+
13+
// Use `createRoot` to create a root, then render the <App /> component
14+
// Note that `createRoot` takes the container DOM node, not the React element
15+
const root = ReactDOM.createRoot(rootDiv)
16+
root.render(<ContentApp />)
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
#extension-root {
6+
position: fixed;
7+
bottom: 0;
8+
right: 0;
9+
z-index: 99999;
10+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/** @type {import('extension-develop').FileConfig} */
2+
module.exports = {
3+
config: (config) => {
4+
config.module.rules.push(
5+
{
6+
test: /\.svg$/i,
7+
type: 'asset',
8+
// *.svg?url
9+
resourceQuery: /url/
10+
},
11+
{
12+
test: /\.svg$/i,
13+
issuer: /\.[jt]sx?$/,
14+
// exclude react component if *.svg?url
15+
resourceQuery: {not: [/url/]},
16+
use: ['@svgr/webpack']
17+
}
18+
)
19+
20+
return config
21+
}
22+
}
Loading
Loading
598 Bytes
Loading
Loading
Lines changed: 9 additions & 0 deletions
Loading
27.8 KB
Loading
Loading
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"manifest_version": 3,
3+
"version": "0.0.1",
4+
"name": "content-react-svgr",
5+
"description": "An Extension.js example.",
6+
"background": {
7+
"chromium:service_worker": "background.ts",
8+
"firefox:scripts": ["background.ts"]
9+
},
10+
"content_scripts": [
11+
{
12+
"matches": ["https://extension.js.org/*"],
13+
"js": ["./content/scripts.tsx"]
14+
}
15+
],
16+
"icons": {
17+
"16": "images/extension_16.png",
18+
"48": "images/extension_48.png",
19+
"128": "images/extension_128.png"
20+
}
21+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"private": true,
3+
"license": "MIT",
4+
"repository": {
5+
"type": "git",
6+
"url": "https://github.com/cezaraugusto/extension.git",
7+
"directory": "programs/create/templates/content-react-svgr"
8+
},
9+
"name": "content-react-svgr",
10+
"description": "An Extension.js example.",
11+
"version": "0.0.1",
12+
"author": {
13+
"name": "Cezar Augusto",
14+
"email": "[email protected]",
15+
"url": "https://cezaraugusto.com"
16+
},
17+
"dependencies": {
18+
"@svgr/webpack": "^8.1.0",
19+
"react": "^18.1.0",
20+
"react-dom": "^18.1.0",
21+
"tailwindcss": "^3.4.1"
22+
},
23+
"devDependencies": {
24+
"@types/react": "^18.0.9",
25+
"@types/react-dom": "^18.0.5",
26+
"typescript": "5.3.3"
27+
}
28+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {}
5+
}
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('tailwindcss').Config} */
2+
module.exports = {
3+
content: ['./content/**/*.tsx'],
4+
theme: {
5+
extend: {}
6+
},
7+
plugins: []
8+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"allowSyntheticDefaultImports": true,
5+
"esModuleInterop": true,
6+
"forceConsistentCasingInFileNames": true,
7+
"isolatedModules": true,
8+
"jsx": "react-jsx",
9+
"lib": ["dom", "dom.iterable", "esnext"],
10+
"moduleResolution": "node",
11+
"module": "esnext",
12+
"noEmit": true,
13+
"resolveJsonModule": true,
14+
"strict": true,
15+
"target": "esnext",
16+
"verbatimModuleSyntax": true,
17+
"useDefineForClassFields": true,
18+
"skipLibCheck": true
19+
},
20+
"include": ["./"],
21+
"exclude": ["node_modules", "dist"]
22+
}

examples/data.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,6 @@ const JS_TEMPLATES: Template[] = [
2929
// hasEnv: false,
3030
// configFiles: ['babel.config.json']
3131
// },
32-
{
33-
name: 'content-extension-config',
34-
uiContext: ['content'],
35-
uiFramework: 'react',
36-
css: 'css',
37-
hasBackground: true,
38-
hasEnv: false,
39-
configFiles: [
40-
'extension.config.js',
41-
'tsconfig.json',
42-
'postcss.config.js',
43-
'tailwind.config.js'
44-
]
45-
},
4632
{
4733
name: 'config-stylelint',
4834
uiContext: ['newTab'],
@@ -261,6 +247,34 @@ const FRAMEWORK_TEMPLATES: Template[] = [
261247
hasEnv: false,
262248
configFiles: ['postcss.config.js', 'tailwind.config.js', 'tsconfig.json']
263249
},
250+
{
251+
name: 'content-extension-config',
252+
uiContext: ['content'],
253+
uiFramework: 'react',
254+
css: 'css',
255+
hasBackground: true,
256+
hasEnv: false,
257+
configFiles: [
258+
'extension.config.js',
259+
'tsconfig.json',
260+
'postcss.config.js',
261+
'tailwind.config.js'
262+
]
263+
},
264+
{
265+
name: 'content-react-svgr',
266+
uiContext: ['content'],
267+
uiFramework: 'react',
268+
css: 'css',
269+
hasBackground: true,
270+
hasEnv: false,
271+
configFiles: [
272+
'extension.config.js',
273+
'tsconfig.json',
274+
'postcss.config.js',
275+
'tailwind.config.js'
276+
]
277+
},
264278
{
265279
name: 'new-vue',
266280
uiContext: ['newTab'],

pnpm-lock.yaml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)