-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathvite.config.prod.ts
More file actions
86 lines (76 loc) · 2.48 KB
/
Copy pathvite.config.prod.ts
File metadata and controls
86 lines (76 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { fileURLToPath, URL } from 'node:url'
import { readFileSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { defineConfig } from 'vite'
import type { Plugin } from 'vite'
import vue from '@vitejs/plugin-vue'
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
import svgLoader from 'vite-svg-loader'
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8')) as {
version: string
}
const userscriptBanner = `// ==UserScript==
// @name eHunter
// @namespace http://tampermonkey.net/
// @version ${pkg.version}
// @description This extension provides a scroll mode and book mode to e-hentai/exhentai/nhentai, for the best reading experince! 此扩展为e-hentai/exhentai/nhentai提供一个滚动模式和书本模式, 提供良好的阅读体验.
// @supportURL https://github.com/hanFengSan/eHunter/issues
// @author Alex Chen
// @match https://exhentai.org/*
// @match https://e-hentai.org/*
// @match https://nhentai.net/*
// @connect hath.network
// @connect nhentai.net
// @connect githubusercontent.com
// @connect jp.animesales.xyz
// @grant GM_xmlhttpRequest
// @grant GM_download
// @license MIT
// ==/UserScript==`
const prependUserscriptBannerPlugin = (): Plugin => ({
name: 'prepend-userscript-banner',
apply: 'build',
enforce: 'post',
writeBundle(outputOptions, bundle) {
const output = bundle['ehunter.iife.js']
if (!output) {
return null
}
const outputDir = outputOptions.dir ?? 'dist'
const outputPath = join(outputDir, 'ehunter.iife.js')
const code = readFileSync(outputPath, 'utf-8')
if (code.startsWith('// ==UserScript==')) {
return null
}
writeFileSync(outputPath, `${userscriptBanner}\n${code}`, 'utf-8')
return null
}
})
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(), cssInjectedByJsPlugin(), svgLoader(), prependUserscriptBannerPlugin()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
__EHUNTER_VERSION__: JSON.stringify(pkg.version)
},
appType: 'custom',
server: {
host: true,
middlewareMode: true,
},
build: {
target: 'es2015',
modulePreload: false,
lib: { // add 30kb size
entry: './src/main.ts',
name: 'ehunter',
formats: ['iife'],
fileName: 'ehunter'
}
}
})