-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathbuild-safari-16.4.js
116 lines (109 loc) · 3.19 KB
/
build-safari-16.4.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* @file Build App-WebView and Safari-Extension resources using the Vite JavaScript API
* @see {@link https://vitejs.dev/guide/api-javascript.html JavaScript API}
*
* Safari supports for modules in background since 16.4
* @see {@link https://developer.apple.com/documentation/safari-release-notes/safari-16_4-release-notes#Safari-Extensions}
* @see {@link https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/background#browser_compatibility}
*
* Content scripts not support import modules, and due to their privileges and the
* speed of injecting user scripts, use a independent build currently
*
* All build processes start at the same time due to asynchronous calls
* The assets name is irrelevant, just need to determine the entry path
*/
import { build } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import pluginMarkedDivest from "./vite-plugin-marked-divest.js";
import * as Utils from "./utils.js";
/** @type {import("vite").InlineConfig} */
const sharedConfig = {
...Utils.baseConfig,
define: {
...Utils.baseConfig.define,
"import.meta.env.SAFARI_VERSION": JSON.stringify(16.4),
},
build: {
sourcemap: process.env.BETA ? true : false,
target: "safari16.4",
},
};
/**
* Build App-Shared WebView resources to xcode dist
*/
build({
...Utils.baseConfig,
plugins: [svelte(), pluginMarkedDivest()],
build: {
...sharedConfig.build,
outDir: `${Utils.APP_SHARED_RESOURCES}/dist/`,
copyPublicDir: false,
rollupOptions: {
input: "entry-app-webview.html",
},
},
});
/**
* Empty resources directory
* Copy public static assets
*/
await Utils.emptyBuildDir(Utils.EXT_SAFARI_RESOURCES);
Utils.cp("public/ext/shared", Utils.EXT_SAFARI_RESOURCES);
Utils.cp("public/ext/safari-16.4", Utils.EXT_SAFARI_RESOURCES);
/** Build content scripts */
[
{ userscripts: "src/ext/content-scripts/entry-userscripts.js" },
{ "dot-user-js": "src/ext/content-scripts/entry-dot-user-js.js" },
{ "script-market": "src/ext/content-scripts/entry-script-market.js" },
].forEach((input) => {
build({
...sharedConfig,
build: {
...sharedConfig.build,
outDir: `${Utils.EXT_SAFARI_RESOURCES}/dist/content-scripts/`,
emptyOutDir: false,
copyPublicDir: false,
rollupOptions: {
input,
output: { entryFileNames: "[name].js" },
},
},
});
});
/**
* Build background scripts
* Modular background may not load correctly on Safari startup
* Currently build classic script separately to avoid this error
*/
build({
...sharedConfig,
build: {
...sharedConfig.build,
outDir: `${Utils.EXT_SAFARI_RESOURCES}/dist/`,
emptyOutDir: false,
copyPublicDir: false,
rollupOptions: {
input: { background: "src/ext/background/main.js" },
output: { entryFileNames: "[name].js" },
},
},
});
/** Build shared modules */
build({
...sharedConfig,
plugins: [svelte()],
publicDir: "public/ext/vendor/",
build: {
...sharedConfig.build,
outDir: `${Utils.EXT_SAFARI_RESOURCES}/dist/`,
emptyOutDir: false,
rollupOptions: {
input: {
// background: "src/ext/background/main.js",
"action-popup": "entry-ext-action-popup.html",
"extension-page": "entry-ext-extension-page.html",
},
output: { entryFileNames: "[name].js" },
},
},
});