-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathtsup.config.ts
85 lines (80 loc) · 2.14 KB
/
tsup.config.ts
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
import { defineConfig } from 'tsup'
import { copy } from 'esbuild-plugin-copy'
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'
import { execSync } from 'child_process'
let latestTag = ''
try {
latestTag = execSync(
'git describe --tags `git rev-list --tags --max-count=1`',
{ encoding: 'utf8' }
).trim()
} catch (error) {
console.error(`执行出错: ${error.message}`)
}
const tag = 'writely-container'
export default defineConfig({
entry: [
'./src/content/index.tsx',
'./src/options/index.tsx',
'./src/popup/index.tsx',
'./src/background/index.ts',
],
target: 'chrome112',
format: 'esm',
splitting: false,
sourcemap: false,
clean: true,
minify: true,
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.version': JSON.stringify(latestTag),
},
injectStyle: (css) => {
return `
var setWritelyStyle = function() {
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = ${css};
if (!chrome.runtime.openOptionsPage) {
setTimeout(() => {
try {
var root = document.getElementsByTagName('${tag}')[0].shadowRoot;
root.appendChild(style);
} catch {
setWritelyStyle()
}
}, 100)
} else {
var root = document.head || document.getElementsByTagName('head')[0];
root.appendChild(style)
}
};
setWritelyStyle();
`
},
outExtension: () => ({ js: '.js' }),
esbuildPlugins: [
NodeModulesPolyfillPlugin(),
copy({
assets: [
{
from: ['./src/options/index.html'],
to: ['./options'],
},
{
from: ['./src/popup/index.html'],
to: ['./popup'],
},
{
from: ['./node_modules/animate.css/animate.css'],
to: ['./content'],
},
{
from: ['./src/assets/*'],
to: ['./assets'],
},
],
watch: process.env.NODE_ENV !== 'production',
}),
],
})