vite-plugin-gas-hoist 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +13 -4
- package/README.md +9 -0
- package/package.json +17 -5
- package/src/index.js +6 -2
package/README.ja.md
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# vite-plugin-gas-hoist
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/vite-plugin-gas-hoist)
|
|
4
|
+
[](https://registry.vite.dev)
|
|
5
|
+
|
|
3
6
|
[English](README.md)
|
|
4
7
|
|
|
5
|
-
エントリーポイントの `export` を Google Apps Script (GAS) のグローバルスコープに公開する Vite
|
|
8
|
+
エントリーポイントの `export` を Google Apps Script (GAS) のグローバルスコープに公開する Vite プラグインです。
|
|
9
|
+
|
|
10
|
+
## 試してみる
|
|
11
|
+
|
|
12
|
+
ブラウザ上でコードの編集とビルドを試すことができます。ビルド完了後、`dist/app.js` を開くとプラグインの出力を確認できます。
|
|
13
|
+
|
|
14
|
+
[](https://stackblitz.com/github/hd140283/vite-plugin-gas-hoist/tree/main/example?file=src/app.js)
|
|
6
15
|
|
|
7
|
-
##
|
|
16
|
+
## なぜ必要か?
|
|
8
17
|
|
|
9
|
-
GAS はグローバルスコープの関数しか実行できないが、Vite でバンドルすると全てのコードが IIFE
|
|
18
|
+
GAS はグローバルスコープの関数しか実行できないが、Vite でバンドルすると全てのコードが IIFE 内に閉じ込められます。このプラグインは、エントリーポイントの `export` を自動的にグローバル関数としてラップすることで、この問題を解決します。
|
|
10
19
|
|
|
11
20
|
```js
|
|
12
21
|
// ビルド前(エントリーポイント)
|
|
@@ -42,7 +51,7 @@ export default defineConfig({
|
|
|
42
51
|
});
|
|
43
52
|
```
|
|
44
53
|
|
|
45
|
-
`build.lib.name` に指定した変数名(上記例では `lib_
|
|
54
|
+
`build.lib.name` に指定した変数名(上記例では `lib_`)を介して、エクスポートされた関数がグローバルスコープに公開されます。
|
|
46
55
|
|
|
47
56
|
## 動作条件
|
|
48
57
|
|
package/README.md
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
# vite-plugin-gas-hoist
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/vite-plugin-gas-hoist)
|
|
4
|
+
[](https://registry.vite.dev)
|
|
5
|
+
|
|
3
6
|
[日本語](README.ja.md)
|
|
4
7
|
|
|
5
8
|
A Vite plugin that hoists entry point `export`s to the global scope for Google Apps Script (GAS).
|
|
6
9
|
|
|
10
|
+
## Try it
|
|
11
|
+
|
|
12
|
+
Edit and build in your browser — no setup required. Once the build finishes, open `dist/app.js` to see the hoisted output.
|
|
13
|
+
|
|
14
|
+
[](https://stackblitz.com/github/hd140283/vite-plugin-gas-hoist/tree/main/example?file=src/app.js)
|
|
15
|
+
|
|
7
16
|
## Why?
|
|
8
17
|
|
|
9
18
|
GAS can only execute functions in the global scope, but Vite bundles all code inside an IIFE. This plugin automatically wraps entry point exports as global functions, bridging the gap.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-gas-hoist",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A Vite plugin that hoists entry point exports to the global scope for Google Apps Script",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite-plugin",
|
|
@@ -23,23 +23,35 @@
|
|
|
23
23
|
"files": [
|
|
24
24
|
"src"
|
|
25
25
|
],
|
|
26
|
+
"compatiblePackages": {
|
|
27
|
+
"schemaVersion": 1,
|
|
28
|
+
"rollup": {
|
|
29
|
+
"type": "incompatible",
|
|
30
|
+
"reason": "Requires Vite's configResolved hook to read build.lib.name"
|
|
31
|
+
},
|
|
32
|
+
"rolldown": {
|
|
33
|
+
"type": "incompatible",
|
|
34
|
+
"reason": "Requires Vite's configResolved hook to read build.lib.name"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
26
37
|
"peerDependencies": {
|
|
27
|
-
"vite": "^8.0.0"
|
|
38
|
+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
28
39
|
},
|
|
29
40
|
"devDependencies": {
|
|
30
41
|
"@biomejs/biome": "^2.3.6",
|
|
31
42
|
"vite": "^8.0.3",
|
|
32
|
-
"
|
|
43
|
+
"vitest": "^4.1.4"
|
|
33
44
|
},
|
|
34
45
|
"volta": {
|
|
35
46
|
"node": "22.21.1",
|
|
36
47
|
"pnpm": "10.23.0"
|
|
37
48
|
},
|
|
38
49
|
"scripts": {
|
|
50
|
+
"test": "vitest run",
|
|
39
51
|
"lint": "biome check --write",
|
|
40
52
|
"lint:ci": "biome check",
|
|
41
|
-
"example:dev": "cd example &&
|
|
42
|
-
"example:build": "cd example &&
|
|
53
|
+
"example:dev": "cd example && npm run dev",
|
|
54
|
+
"example:build": "cd example && npm run build",
|
|
43
55
|
"example:login": "pnpx @google/clasp@2.5 login",
|
|
44
56
|
"example:push": "cd example && pnpx @google/clasp@2.5 push"
|
|
45
57
|
}
|
package/src/index.js
CHANGED
|
@@ -25,10 +25,11 @@ export const vitePluginGasHoist = () => {
|
|
|
25
25
|
|
|
26
26
|
return {
|
|
27
27
|
name: 'vite-plugin-gas-hoist',
|
|
28
|
+
apply: 'build',
|
|
28
29
|
|
|
29
30
|
/** @param {import('vite').ResolvedConfig} config */
|
|
30
31
|
configResolved(config) {
|
|
31
|
-
varName = config.build.lib
|
|
32
|
+
varName = config.build.lib?.name;
|
|
32
33
|
},
|
|
33
34
|
|
|
34
35
|
renderChunk: {
|
|
@@ -55,7 +56,10 @@ export const vitePluginGasHoist = () => {
|
|
|
55
56
|
.map((name) => `function ${name}(...args){return ${varName}.${name}(...args)}`)
|
|
56
57
|
.join('\n');
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
const label = exports.length === 1 ? 'function' : 'functions';
|
|
60
|
+
const list = exports.map((name) => ` - ${name}`).join('\n');
|
|
61
|
+
console.log(`[vite-plugin-gas-hoist] Hoisted ${exports.length} ${label} to global scope:\n${list}`);
|
|
62
|
+
|
|
59
63
|
return `${code}\n${wrappers}\n`;
|
|
60
64
|
},
|
|
61
65
|
},
|