lisonge / vite-plugin-monkey Goto Github PK
View Code? Open in Web Editor NEWA vite plugin server and build your.user.js for userscript engine like Tampermonkey, Violentmonkey, Greasemonkey, ScriptCat
License: MIT License
A vite plugin server and build your.user.js for userscript engine like Tampermonkey, Violentmonkey, Greasemonkey, ScriptCat
License: MIT License
使用以下 config 搭配 vite build --watch
monkey({
build: {
externalGlobals: {
'sentinel-js': cdn.cdnjs('sentinel', 'sentinel.min.js'),
}
}
})
触发多次rebuild后会得到
// ==UserScript==
// @name 知乎助手
// @namespace pionxzh
// @version 1.0.0
// @author pionxzh
// @description 自动屏蔽来自黑名单的所有评论与文章
// @license MIT
// @icon https://static.zhihu.com/heifetz/favicon.ico
// @match *.zhihu.com/*
// @require https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.min.js
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
Uncaught ReferenceError: MONKEY_WINDOW is not defined
1.x和2.00都有这个情况, 导致开发模式不顺利
.meta.js
只会包含 UserScript 注释,不包含代码正文,Tampermonkey 等脚本插件会自动使用该文件检查脚本更新而不必下载完整脚本,Greasy Fork 等脚本托管网站也会自动提供该文件(可以随便找个脚本链接把 .user.js
替换为 .meta.js
访问看看)
如果是使用 Github Pages 等托管脚本的话,自动生成 .meta.js
会很有用
例如我需要获取 GM_xmlhttpRequest
参数中 responseType
的类型,目前只能这么写
Parameters<typeof GM_xmlhttpRequest>['0']['responseType']
但如果有导出类型 XhrRequest
,就可以简化成
XhrRequest['responseType']
...
userscript: {
...
antifeature: {
type: "tracking",
description: "test"
},
...
},
...
build:
// @antifeature trackingtest
vite.config.js
import { defineConfig } from 'vite';
import monkey from 'vite-plugin-monkey';
import eslintPlugin from 'vite-plugin-eslint';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
monkey({
entry: 'src/main.js',
userscript: {
icon: 'https://vitejs.dev/logo.svg',
namespace: 'npm/vite-plugin-monkey',
match: ['*://github.com/*'],
'run-at': 'document-end',
},
}),
eslintPlugin(),
],
});
main.js
console.log('lala');
报错文字如下:
userscript.html?name=server%253Agithub.user.js&id=8a1c944e-1d66-47f8-8d2c-fb2eef8448a2:79 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' github.githubassets.com". Either the 'unsafe-inline' keyword, a hash ('sha256-m9WuhxCDjalzF2tBhg/f0YTfasIeLnFGhEK6+zp1IZw='), or a nonce ('nonce-...') is required to enable inline execution.
如果说 github 做了限制,那么其他脚本应该也无法正常运行。但我只是简单的加了一个 console.log
就无法运行,感觉是不是哪里出问题了。
Search · 1a1a1a:
https://github.com/lisonge/vite-plugin-monkey/search?q=1a1a1a
background-color: #1a1a1a;
→ border-color: #1a1a1a
;
目测这里是想定义边框样式……
~/project/luogu/luogu-ex-backstage $ vite build
vite v2.9.13 building for production...
✓ 26 modules transformed.
Invalid value "iife" for option "output.format" - UMD and IIFE output formats are not supported for code-splitting builds.
error during build:
Error: Invalid value "iife" for option "output.format" - UMD and IIFE output formats are not supported for code-splitting builds.
at error (/usr/local/lib/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:198:30)
at validateOptionsForMultiChunkOutput (/usr/local/lib/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:16265:16)
at Bundle.generate (/usr/local/lib/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:16099:17)
at async /usr/local/lib/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:23732:27
at async catchUnfinishedHookActions (/usr/local/lib/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:23174:20)
at async doBuild (/usr/local/lib/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:41696:26)
at async build (/usr/local/lib/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:41527:16)
at async CAC.<anonymous> (/usr/local/lib/node_modules/vite/dist/node/cli.js:738:9)
此处的 else if 在扩展名判断处断开了,导致扩展名处理会覆盖 raw / url 的处理,按理来说应该全部用 else if 连接
pinia
依赖 vue-demi
但是当我写在 externalGlobals
里时不会自动导入
估计是没有安装和没引用 但是 pinia
里确实使用到了该包
根据 https://greasyfork.org/zh-CN/help/meta-keys#meta-name-localized
希望可以提供某种方式来配置这种语言相关的meta
@name:XX-YY
脚本在特定语言区域的标题。XX 指 ISO 639-1 国家代码 以及 YY 指可选的 ISO 3166 地区代码。该选项用于提供多语言的@name 脚本名称。
@description:XX-YY
用某门语言写成的脚本描述。XX 指 ISO 639-1 国家代码 以及 YY 指可选的 ISO 3166 地区代码。该选项用于提供多语言的@description 脚本介绍。
例如 include: /^xxx$/
输出获得 // @include ^xxx$
,是错误的,应当输出 // @include /^xxx$/
After initializing the project, the following error is reported when executing npm run dev
在初始化项目之后,执行 npm run dev的时候报如下错误
`
shell
npm create monkey
cd xxx
npm install
npm run dev
`
[email protected] dev
vite
failed to load config from /Users/xxx/Code/xxx_plugin/vite.config.ts
error when starting dev server:
SyntaxError: Unexpected token '||='
at Loader.moduleStrategy (internal/modules/esm/translators.js:145:18)
updated to 2023-07-20 20:48
Refused to load the script 'http://127.0.0.1:3000/@vite/client' because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'self' data: 'unsafe-inline' https://checkout.stripe.com/checkout.js https://checkout.stripe.com https://js.stripe.com/v3 https://platform.twitter.com/widgets.js https://static.npmjs.com/". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
(匿名) @ userscript.html?name=dev%253Avite-userscript-template.user.js&id=289d436b-2813-44f5-b751-16c871c6e093:105
10:25:04.643 userscript.html?name=dev%253Avite-userscript-template.user.js&id=289d436b-2813-44f5-b751-16c871c6e093:105
Refused to load the script 'http://127.0.0.1:3000/src/main.ts' because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'self' data: 'unsafe-inline' https://checkout.stripe.com/checkout.js https://checkout.stripe.com https://js.stripe.com/v3 https://platform.twitter.com/widgets.js https://static.npmjs.com/". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
我感觉在 resource 里添加 cdn 上的 css 这种使用方式挺常见的,能否让 resource 跟 externalGlobals 一样支持使用 cdn 工具函数
(想了下好像不太对,应该是需要一种新的 cdn 工具函数能直接返回 cdn 地址字符串,主要是为了可以动态获取版本号)
package.json
{
"name": "vite-vue-typescript-starter",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.2.37"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.3.3",
"typescript": "^4.6.4",
"vite": "^2.9.13",
"vue-tsc": "^0.38.2",
"vite-plugin-monkey": "0.2.13"
}
}
when set "type": "module",
plugin can not found module
Discussed in #55
Caused by Tampermonkey/tampermonkey#1567
看代码没有 export,不能直接 import 这个类型
这样倒是可以,但感觉不太好
import type { MonkeyOption } from 'vite-plugin-monkey/src/node/types';
The author
field in package.json
can be specified as a string or the object
{
name: string,
email?: string,
url?: string,
}
In the latter case, the author.name
is used as the userscript name instead of the name
field from package.json
which is of course incorrect.
If package.json
has the following fields:
"name": "script_name",
"author": {
"name": "author_name"
},
the userscript will be compiler with the name author_name
instead of script_name
.
前提:只修改了vite.config.js中的match。
控制台:
Uncaught TypeError: Failed to resolve module specifier "vue". Relative references must start with either "/", "./", or "../".
how can i use jquery in svelte template?
Covert Beta and Alpha releases to pre-releases
例如
// @require https://unpkg.com/[email protected]//dist/vue.global.prod.js
// @require https://unpkg.com/[email protected]//dist/index.full.js // element-plus 依赖 vue
vue.js 会导出一个变量 Vue
,element 会寻找 this.Vue
当成依赖,但是在油猴的环境中 this 被重定向到了 window 的一个 proxy(@grant none
就会指向空对象),所以就会发生报错说 vue is not found
,即使 vue 变量已经在环境中了。
所以能不能提供一个自定义依赖引入的方法呢?
Windows 10
Chrome v83
vite-plugin-monkey v2.10.0
设置了vite构建选项build.cssTarget
,npm run build
后发现,HelloWorld.vue
里.read-the-docs
的定位样式被编译为了inset:60px 0 0 260px;
,而inset
是chrome87才开始支持的,所以似乎是某种处理导致build.cssTarget
没有生效。
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import monkey, { cdn } from 'vite-plugin-monkey';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
monkey({
entry: 'src/main.ts',
userscript: {
icon: 'https://vitejs.dev/logo.svg',
namespace: 'npm/vite-plugin-monkey',
match: ['https://www.google.com/'],
},
build: {
minifyCss: true,
externalGlobals: {
vue: cdn.jsdelivr('Vue', 'dist/vue.global.prod.js'),
},
},
}),
],
build: {
cssTarget: 'chrome83',
}
});
<style scoped>
.read-the-docs {
color: #888;
position: fixed;
top: 60px;
right: 0;
bottom: 0;
left: 260px;
background: #fff;
z-index: 1050;
padding: 10px 20px 200px 20px;
overflow-y: auto;
box-shadow: -2px 2px 6px #bbbbbb;
}
</style>
麻烦大神看一下是怎么回事,感谢!
开发时候是正常运行的,但是打包以后复制到油猴脚本里面刷新页面。
有一个Uncaught SyntaxError: Unexpected token ','
这样的报错
我试了一下把tsconfig的target改成es5,还有取消cdn,build出来的还是报错。
如以下 js 代码:
ClickSelector('button', '确认')
在打包后会变成:
ClickSelector("button", "\u786E\u8BA4");
用倒是能用,但是在油猴插件中直接查看代码的时候就看不懂写的是什么了。
使用命令「pnpm run dev」预览脚本,添加脚本后打开匹配网站,在控制台出现如下错误
Use the command "pnpm run dev" to preview the project, an error occurred at the console, the project preview failed.
client.ts:470:16 in
style.css:1:96 in
修改vite.config.js 中的
Modify the file "vite.config.js "
当我直接构建项目然后导入至油猴插件时,脚本就能正常运行了。
我尝试过直接使用模板在该网站预览,还是会发生同样的错误。
使用该项目在其他网站预览(例如哔哩哔哩),就不会发生这种问题。
When I build the project directly and import it into the Monkey, the script works fine.
I preview the template project on the website and the same error still occurs.
If i preview the project on other websites ( For example, bilibili ), the error does not occur.
以上就是我的问题了,感谢大佬抽空查看我的问题,如果有解决方案就更好了。(一个前端小白)也许我可能遗留了某些配置文件吧,求大佬轻喷。
@vitejs/plugin-react
will inject
<script type="module">
import RefreshRuntime from "/@react-refresh"
RefreshRuntime.injectIntoGlobalHook(window)
window.$RefreshReg$ = () => {}
window.$RefreshSig$ = () => (type) => type
window.__vite_plugin_react_preamble_installed__ = true
</script>
to index.html document.head
but vite-plugin-monkey
existing installation mode will just inject /@vite/client
and /src/main.jsx
so React
and @vitejs/plugin-react
can not work with vite-plugin-monkey
finallly, vite-plugin-monkey
need to use other installation
I am adding a package that is in the beta:
npm install @formkit/vue
npm show @formkit/vue
# @formkit/[email protected]
Then I set up the CDN:
'@formkit/vue': cdn.jsdelivr('FormKit', 'dist/formkit-vue.js'),
During the build, the following message appears:
[plugin-monkey] not found module @formkit/vue version, use @formkit/vue@latest
The resulting file has an invalid URL to the package:
// @require https://cdn.jsdelivr.net/npm/@formkit@latest/dist/formkit-vue.js
I am using the following workaround:
'@formkit/vue': [
'FormKit',
(version: string) => `https://cdn.jsdelivr.net/npm/@formkit/vue@${version}/dist/formkit-vue.js`,
],
// @require https://cdn.jsdelivr.net/npm/@formkit/vue@latest/dist/formkit-vue.js
I am developing a SvelteKit website which in I do host my Tampermonkey's userscripts.
I can't manage to make the plugin be built after I added my svelte website to the repo.
adding
rollupOptions: {
output: {
inlineDynamicImports: false,
},
},
in the build
vite config option doesn't work as SvelteKit:
The following Vite config options will be overridden by SvelteKit:
- build.rollupOptions.input
import { defineConfig } from 'vite';
import monkey, { cdn } from 'vite-plugin-monkey';
import cleanCss from './plugins/cleanCss';
import fs from 'node:fs/promises';
import type PrettierPkgR from 'prettier/package.json';
const prettierPkg: typeof PrettierPkgR = JSON.parse(
(await fs.readFile('./node_modules/prettier/package.json')).toString('utf-8')
);
const pkgBaseUrl = 'https://unpkg.com/pkg-cdn/dist/';
const prettierCdn = (pkg: string) => {
return [
`prettierPlugins.${pkg}`,
`https://cdn.jsdelivr.net/npm/prettier@${prettierPkg.version}/parser-${pkg}.js`,
] as [string, string];
};
export default defineConfig(({ command }) => {
const multi = <T1, T2>(serve: T1, build: T2) => {
return command == 'serve' ? serve : build;
};
return {
plugins: [
cleanCss(),
monkey({
entry: 'src/main.ts',
userscript: {
icon: 'https://vitejs.dev/logo.svg',
name: 'v2ex评论markdown支持',
description: 'v2ex评论markdown支持;代码语法高亮;代码自动格式化',
namespace: 'https://github.com/lisonge',
match: ['https://v2ex.com/t/*', 'https://www.v2ex.com/t/*'],
version: multi('0.0.0', undefined),
},
build: {
externalGlobals: {
'markdown-it': cdn.jsdelivr(
'markdownit',
'dist/markdown-it.min.js'
),
'highlight.js': [
'hljs',
(version) => {
return `https://unpkg.com/@highlightjs/cdn-assets@${version}/highlight.min.js`;
},
],
prettier: cdn.jsdelivr('prettier', 'standalone.js'),
'prettier/parser-babel': prettierCdn('babel'),
'prettier/parser-yaml': prettierCdn('yaml'),
'prettier/parser-postcss': prettierCdn('postcss'),
'prettier/parser-html': prettierCdn('html'),
'prettier-plugin-java': [
'PrettierPluginJava',
(version) =>
`${pkgBaseUrl}prettier-plugin-java/v${version}.umd.js`,
],
},
},
}),
],
};
});
submodule prettier/*
get version is always latest
/src
├── assets
│ ├── javascript.svg
│ └── vite.svg
├── style
│ └── style.css
└── utils
└── counter.js
我看到 externalResource 里面有处理 ?raw
因此我猜想我应该是可以这样使用的
import { GM_addStyle } from '$';
import elementPlusCss from 'element-plus/dist/index.css?raw';
// 自行在某个需要的时候才动态引入
GM_addStyle(elementPlusCss);
// in monkey config
externalResource: {
'element-plus/dist/index.css?raw': cdn.jsdelivrFastly(undefined, 'dist/index.css'),
}
但实际上不管用,经过测试我发现,问题出在这里
不知道为什么此处 id 实际为 element-plus/dist/index.css?used&raw
,多了个 used&
,导致没有匹配上 externalResource
将 externalResource 配置里的 key 改为 element-plus/dist/index.css?used&raw
就可以顺利走进 load 钩子了,不过因为结尾并不是 ?raw
因此没有匹配上 raw 的处理,还是会有问题
在shared/userscript-config/src/index.ts
中引入了vite-plugin-monkey/dist/client
中的方方法GM_getValue
,用于某个自定义方法,在packages/gitrec
中使用该自定义方法。而在构建packages/gitrec
时,提示如下信息:
ReferenceError: __MONKEY_WINDOW__ is not defined
at file:///home/runner/work/userscripts-lisonge/userscripts-lisonge/shared/userscript-config/dist/index.js:2:20
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:526:24)
at async loadConfigFromBundledFile (file:///home/runner/work/userscripts-lisonge/userscripts-lisonge/node_modules/.pnpm/[email protected]_lx63oaw2dyx6c23wnkvjnvox4q/node_modules/vite/dist/node/chunks/dep-ca21228b.js:62337:21)
at async loadConfigFromFile (file:///home/runner/work/userscripts-lisonge/userscripts-lisonge/node_modules/.pnpm/[email protected]_lx63oaw2dyx6c23wnkvjnvox4q/node_modules/vite/dist/node/chunks/dep-ca21228b.js:62222:28)
at async resolveConfig (file:///home/runner/work/userscripts-lisonge/userscripts-lisonge/node_modules/.pnpm/[email protected]_lx63oaw2dyx6c23wnkvjnvox4q/node_modules/vite/dist/node/chunks/dep-ca21228b.js:6[18](https://github.com/northsea4/userscripts-lisonge/actions/runs/4288608080/jobs/7470804904#step:7:19)43:28)
at async build (file:///home/runner/work/userscripts-lisonge/userscripts-lisonge/node_modules/.pnpm/[email protected]_lx63oaw2dyx6c23wnkvjnvox4q/node_modules/vite/dist/node/chunks/dep-ca21228b.js:44512:[20](https://github.com/northsea4/userscripts-lisonge/actions/runs/4288608080/jobs/7470804904#step:7:21))
at async CAC.<anonymous> (file:///home/runner/work/userscripts-lisonge/userscripts-lisonge/node_modules/.pnpm/[email protected]_lx63oaw2dyx6c23wnkvjnvox4q/node_modules/vite/dist/node/cli.js:813:9)
undefined
/home/runner/work/userscripts-lisonge/userscripts-lisonge/packages/gitrec:
ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL [email protected] build: `vite build`
请查看 复现项目,最新的workflow pnpm version 7。
也可以fork该测试仓库后手动运行 Test
这个workflow。
具体的测试代码请在commit test 中查看。
感谢抽空查看我问题,我是前端新手,所以对问题的描述可能有点混乱,请见谅。
注意:问题出现在使用
build
命令时,dev
指令不会出现该错误
项目是以纯ts
模式开发的,运行vite build
出现以下错误:
PS G:\Code\tampermokey\steam-price-exchanger> vite build
vite v3.1.4 building for production...
✓ 14 modules transformed.
Module format iife does not support top-level await. Use the "es" or "system" output formats rather.
file: G:\Code\tampermokey\steam-price-exchanger\src\main.ts
error during build:
Error: Module format iife does not support top-level await. Use the "es" or "system" output formats rather.
at error (file:///G:/Code/tampermokey/steam-price-exchanger/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
at Chunk.render (file:///G:/Code/tampermokey/steam-price-exchanger/node_modules/rollup/dist/es/shared/rollup.js:14844:20)
at file:///G:/Code/tampermokey/steam-price-exchanger/node_modules/rollup/dist/es/shared/rollup.js:16006:52
at Array.map (<anonymous>)
at Bundle.addFinalizedChunksToBundle (file:///G:/Code/tampermokey/steam-price-exchanger/node_modules/rollup/dist/es/shared/rollup.js:16004:34)
at Bundle.generate (file:///G:/Code/tampermokey/steam-price-exchanger/node_modules/rollup/dist/es/shared/rollup.js:15984:24)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///G:/Code/tampermokey/steam-price-exchanger/node_modules/rollup/dist/es/shared/rollup.js:23754:27
at async catchUnfinishedHookActions (file:///G:/Code/tampermokey/steam-price-exchanger/node_modules/rollup/dist/es/shared/rollup.js:23088:20)
at async doBuild (file:///G:/Code/tampermokey/steam-price-exchanger/node_modules/vite/dist/node/chunks/dep-6b3a5aff.js:45818:26)
可在此处查看项目代码
在main.ts
中使用await
关键字,执行vite build
指令失败,例如:
import {main} from './realMain'
await main()
在main.ts
中不使用await
关键字,执行vite build
指令成功,例如:
import {main} from './realMain'
main().then()
可以在此处获取项目的源码
{
"compilerOptions": {
"experimentalDecorators": true,
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": [
"ESNext",
"DOM"
],
"moduleResolution": "Node",
"strict": true,
"sourceMap": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true
},
"include": [
"src"
]
}
import {defineConfig} from 'vite'
import monkey from 'vite-plugin-monkey'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
monkey({
entry: 'src/main.ts',
userscript: {
name: 'steam价格转换',
author: 'marioplus',
description: 'steam商店中的价格转换为人民币',
version: '1.0.0',
icon: 'https://vitejs.dev/logo.svg',
namespace: 'marioplus/steam-price-exchanger',
match: [
'https://store.steampowered.com/*',
'https://steamcommunity.com/*'
],
connect: [
'open.er-api.com',
'store.steampowered.com'
]
},
}),
],
})
将修改vite配置增加 build
配置
export default defineConfig({
build: {
lib: {
entry: 'src/main.ts',
formats: ['es'],
},
target: 'esnext'
}
...
})
会出现以下错误
"C:\Program Files\nodejs\npm.cmd" run build
> [email protected] build
> tsc && vite build
vite v3.1.4 building for production...
✓ 15 modules transformed.
dist/steam-price-converter.user.js 90.44 KiB / gzip: 18.08 KiB
Module format iife does not support top-level await. Use the "es" or "system" output formats rather.
file: G:\Code\tampermokey\steam-price-converter\src\main.ts
error during build:
Error: Module format iife does not support top-level await. Use the "es" or "system" output formats rather.
at error (file:///G:/Code/tampermokey/steam-price-converter/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
at Chunk.render (file:///G:/Code/tampermokey/steam-price-converter/node_modules/rollup/dist/es/shared/rollup.js:14844:20)
at file:///G:/Code/tampermokey/steam-price-converter/node_modules/rollup/dist/es/shared/rollup.js:16006:52
at Array.map (<anonymous>)
at Bundle.addFinalizedChunksToBundle (file:///G:/Code/tampermokey/steam-price-converter/node_modules/rollup/dist/es/shared/rollup.js:16004:34)
at Bundle.generate (file:///G:/Code/tampermokey/steam-price-converter/node_modules/rollup/dist/es/shared/rollup.js:15984:24)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///G:/Code/tampermokey/steam-price-converter/node_modules/rollup/dist/es/shared/rollup.js:23754:27
at async catchUnfinishedHookActions (file:///G:/Code/tampermokey/steam-price-converter/node_modules/rollup/dist/es/shared/rollup.js:23088:20)
at async doBuild (file:///G:/Code/tampermokey/steam-price-converter/node_modules/vite/dist/node/chunks/dep-6b3a5aff.js:45818:26)
虽然出现了错误,但dist
文件夹有构建脚本输出,且脚本能正常使用
export default defineConfig(async ({ command, mode }) => ({
plugins: [
monkey({
entry: 'src/entry1.ts',
userscript: {
// ...
},
build: {
fileName: 'out1.user.js',
},
}),
monkey({
entry: 'src/entry2.ts',
userscript: {
// ...
},
build: {
fileName: 'out2.user.js',
},
}),
]
Currently only out2.user.js
is written, containing both userscript headers, which does not work with tampermonkey.
使用场景: 当脚本定义了大量可配置项 得在两个脚本间不断开关调试, 非常难受, 想参考 https://github.com/the1812/Bilibili-Evolved 的 dev client 功能, 但是那个是基于 webpack 开发的, 换成 vite 就没思路不会写了
Hello again!
I have two vite.config
files:
vite.config.ts
: for my sveltekit websiteuserscript.vite.config.ts
: for my static asset (a tampermonkey userscript using the vite-plugin-monkey
pluggin)My build
and preview
works, for both of the config files, but my dev
doesn't work for userscript.vite.config.ts
.
userscript.vite.config.ts
import { defineConfig } from 'vite';
import monkey from 'vite-plugin-monkey';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
monkey({
entry: 'external/script.user.ts',
userscript: {
namespace: 'https://github.com/EFRAUDE/Moodle',
},
}),
],
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.