This commit is contained in:
Guo Yunhe
2024-03-04 22:43:53 +08:00
parent 72125d402d
commit d33a8db65e
11 changed files with 187 additions and 48 deletions
+2 -1
View File
@@ -6,5 +6,6 @@ end_of_line = lf
indent_size = 2 indent_size = 2
indent_style = space indent_style = space
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true max_line_length = 100
quote_type = single quote_type = single
trim_trailing_whitespace = true
+40
View File
@@ -0,0 +1,40 @@
name: CI
on:
- push
- pull_request
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: pnpm/action-setup@v3
with:
version: latest
- run: pnpm install
- run: pnpm run lint
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: pnpm/action-setup@v3
with:
version: latest
- run: pnpm install
- run: pnpm run test
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: pnpm/action-setup@v3
with:
version: latest
- run: pnpm install
- run: pnpm run build
+29
View File
@@ -0,0 +1,29 @@
name: GitHub Pages
on:
push:
branches:
- main
pull_request:
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: pnpm/action-setup@v3
with:
version: latest
- run: pnpm install
- run: pnpm run build
- uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
+4 -12
View File
@@ -1,16 +1,8 @@
# Build output .rive
dist build
# Coverage directory
coverage coverage
dist
# Dependency directories node_modules
node_modules/
# Lock files
package-lock.json package-lock.json
pnpm-lock.yaml pnpm-lock.yaml
yarn.lock yarn.lock
# Output of 'npm pack'
*.tgz
+4 -2
View File
@@ -2,6 +2,8 @@
"recommendations": [ "recommendations": [
"dbaeumer.vscode-eslint", "dbaeumer.vscode-eslint",
"editorconfig.editorconfig", "editorconfig.editorconfig",
"esbenp.prettier-vscode" "esbenp.prettier-vscode",
"stylelint.vscode-stylelint",
"unifiedjs.vscode-mdx"
] ]
} }
+33 -4
View File
@@ -1,11 +1,14 @@
{ {
"eslint.validate": [ "eslint.validate": [
"javascript", "javascript",
"typescript" "typescript",
"javascriptreact",
"typescriptreact"
], ],
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.fixAll.eslint": true, "source.fixAll.eslint": "explicit",
"source.organizeImports": true "source.organizeImports": "explicit",
"source.fixAll.stylelint": "explicit"
}, },
"editor.defaultFormatter": "esbenp.prettier-vscode", "editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true, "editor.formatOnSave": true,
@@ -23,5 +26,31 @@
}, },
"[jsonc]": { "[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "esbenp.prettier-vscode"
},
"stylelint.validate": [
"css",
"less",
"scss"
],
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[less]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[scss]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
} }
} }
+2 -2
View File
@@ -1,5 +1,5 @@
# Changelog # Changelog
## 1.0.0 - 2023-03-30 ## 2024-03-04
- First version, support `client` option and `VITE_ADSENSE_CLIENT` env - Changed license to MIT
+16
View File
@@ -15,6 +15,8 @@ npm i vite-plugin-adsense
## Usage ## Usage
It is recommended to save your client id into `.env` file.
```ini ```ini
# .env # .env
VITE_ADSENSE_CLIENT=ca-pub-1234567890123456 VITE_ADSENSE_CLIENT=ca-pub-1234567890123456
@@ -29,3 +31,17 @@ export default defineConfig({
plugins: [adsense()], plugins: [adsense()],
}); });
``` ```
If you have more advanced usage, you can also pass `client` to plugin options.
```ts
// vite.config.ts
import { defineConfig } from 'vite';
import adsense from 'vite-plugin-adsense';
export default defineConfig({
plugins: [adsense({
client: 'ca-pub-1234567890123456',
})],
});
```
+30 -22
View File
@@ -19,14 +19,15 @@
"url": "git+https://github.com/guoyunhe/vite-plugin-adsense.git" "url": "git+https://github.com/guoyunhe/vite-plugin-adsense.git"
}, },
"funding": "https://github.com/sponsors/guoyunhe", "funding": "https://github.com/sponsors/guoyunhe",
"license": "GPL-3.0", "license": "MIT",
"author": { "author": {
"name": "Guo Yunhe", "name": "Guo Yunhe",
"email": "i@guoyunhe.me" "email": "i@guoyunhe.me"
}, },
"type": "module", "type": "module",
"main": "dist/index.mjs", "main": "dist/cjs/index.js",
"typings": "dist/index.d.ts", "module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [ "files": [
"dist", "dist",
"CHANGELOG.md", "CHANGELOG.md",
@@ -34,28 +35,35 @@
"README.md" "README.md"
], ],
"scripts": { "scripts": {
"build": "node-scripts build", "build": "rive build",
"format": "node-scripts format", "build:watch": "rive build --watch",
"lint": "node-scripts lint", "lint": "rive lint",
"test": "node-scripts test", "lint:fix": "rive lint --fix",
"watch": "node-scripts watch" "start": "rive start",
}, "test": "rive test",
"prettier": { "test:ui": "rive test --ui",
"printWidth": 100, "test:watch": "rive test --watch"
"singleQuote": true
}, },
"prettier": "prettier-config-rive",
"eslintConfig": { "eslintConfig": {
"extends": "@guoyunhe/node-scripts" "extends": "eslint-config-rive"
},
"jest": {
"preset": "@guoyunhe/node-scripts"
}, },
"devDependencies": { "devDependencies": {
"@guoyunhe/node-scripts": "^2.0.0", "@mdx-js/react": "^3.0.1",
"@tsconfig/node16": "^1.0.0", "@types/node": "^16.18.86",
"@types/jest": "^29.0.0", "@types/react": "^18.2.61",
"@types/node": "^16.0.0", "@types/react-dom": "^18.2.19",
"typescript": "^4.0.0", "react": "^18.2.0",
"vite": "^4.2.1" "react-doc-ui": "^2.2.6",
"react-dom": "^18.2.0",
"rive": "^2.0.33",
"typescript": "^5.3.3"
},
"rive": {
"template": "node",
"doc": {
"basename": "/vite-plugin-adsense/"
}
} }
} }
+2 -2
View File
@@ -24,7 +24,7 @@ export default function adsense({ client }: AdSenseOptions = {}): Plugin {
// insert adsense script to the end of index.html // insert adsense script to the end of index.html
return html.replace( return html.replace(
/<\/body>/, /<\/body>/,
` <script src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${actualClient}" crossorigin="anonymous" defer></script>\n</body>` ` <script src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${actualClient}" crossorigin="anonymous" defer></script>\n</body>`,
); );
}, },
closeBundle: async () => { closeBundle: async () => {
@@ -34,7 +34,7 @@ export default function adsense({ client }: AdSenseOptions = {}): Plugin {
// create ads.txt file // create ads.txt file
await writeFile( await writeFile(
join(outDir, 'ads.txt'), join(outDir, 'ads.txt'),
`google.com, ${actualClient.substring(3)}, DIRECT, f08c47fec0942fa0\n` `google.com, ${actualClient.substring(3)}, DIRECT, f08c47fec0942fa0\n`,
); );
}, },
}; };
+25 -3
View File
@@ -1,8 +1,30 @@
{ {
"extends": "@tsconfig/node16/tsconfig.json",
"compilerOptions": { "compilerOptions": {
"resolveJsonModule": true, "resolveJsonModule": true,
"types": ["node", "jest", "@guoyunhe/node-scripts/global"] "types": [
"node",
"rive/globals"
],
"target": "es2015",
"lib": [
"esnext"
],
"allowJs": true,
"checkJs": false,
"skipLibCheck": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"isolatedModules": true
}, },
"include": ["src"] "include": [
"src"
],
"exclude": [
".rive",
"build",
"coverage",
"dist",
"node_modules"
]
} }