@tomjs/vite-plugin-vscode 1.2.0 → 1.3.0
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.md +15 -6
- package/README.zh_CN.md +15 -24
- package/dist/index.js +45 -4
- package/dist/index.mjs +45 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ private _getWebviewContent(webview: Webview, extensionUri: Uri) {
|
|
|
88
88
|
|
|
89
89
|
if (process.env.VITE_DEV_SERVER_URL) {
|
|
90
90
|
// @ts-ignore
|
|
91
|
-
return
|
|
91
|
+
return __getWebviewHtml__({ serverUrl: process.env.VITE_DEV_SERVER_URL });
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// Tip: Install the es6-string-html VS Code extension to enable code highlighting below
|
|
@@ -223,9 +223,17 @@ Based on [Options](https://paka.dev/npm/tsup) of [tsup](https://tsup.egoist.dev/
|
|
|
223
223
|
|
|
224
224
|
`vscode extension` use.
|
|
225
225
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
|
226
|
+
- `development` mode
|
|
227
|
+
|
|
228
|
+
| Variable | Description |
|
|
229
|
+
| --------------------- | ------------------------------- |
|
|
230
|
+
| `VITE_DEV_SERVER_URL` | The url of the vite dev server. |
|
|
231
|
+
|
|
232
|
+
- `production` mode
|
|
233
|
+
|
|
234
|
+
| Variable | Description |
|
|
235
|
+
| --- | --- |
|
|
236
|
+
| `VITE_DIST_FILES` | All js files in the dist directory, excluding index.js. It's to be a json string. |
|
|
229
237
|
|
|
230
238
|
## Debug
|
|
231
239
|
|
|
@@ -299,5 +307,6 @@ pnpm build
|
|
|
299
307
|
|
|
300
308
|
Open the [examples](./examples) directory, there are `vue` and `react` examples.
|
|
301
309
|
|
|
302
|
-
- [react](./examples/react)
|
|
303
|
-
- [vue](./examples/vue)
|
|
310
|
+
- [react](./examples/react): simple react example.
|
|
311
|
+
- [vue](./examples/vue): simple vue example.
|
|
312
|
+
- [vue-import](./examples/vue-import): dynamic import() example.
|
package/README.zh_CN.md
CHANGED
|
@@ -80,15 +80,15 @@ const panel = window.createWebviewPanel('showHelloWorld', 'Hello World', ViewCol
|
|
|
80
80
|
```ts
|
|
81
81
|
private _getWebviewContent(webview: Webview, extensionUri: Uri) {
|
|
82
82
|
// The CSS file from the Vue build output
|
|
83
|
-
const stylesUri = getUri(webview, extensionUri, ['dist
|
|
83
|
+
const stylesUri = getUri(webview, extensionUri, ['dist/webview/assets/index.css']);
|
|
84
84
|
// The JS file from the Vue build output
|
|
85
|
-
const scriptUri = getUri(webview, extensionUri, ['dist
|
|
85
|
+
const scriptUri = getUri(webview, extensionUri, ['dist/webview/assets/index.js']);
|
|
86
86
|
|
|
87
87
|
const nonce = uuid();
|
|
88
88
|
|
|
89
89
|
if (process.env.VITE_DEV_SERVER_URL) {
|
|
90
90
|
// @ts-ignore
|
|
91
|
-
return
|
|
91
|
+
return __getWebviewHtml__({ serverUrl: process.env.VITE_DEV_SERVER_URL });
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// Tip: Install the es6-string-html VS Code extension to enable code highlighting below
|
|
@@ -140,15 +140,6 @@ export default defineConfig({
|
|
|
140
140
|
}),
|
|
141
141
|
vscode(),
|
|
142
142
|
],
|
|
143
|
-
build: {
|
|
144
|
-
rollupOptions: {
|
|
145
|
-
output: {
|
|
146
|
-
entryFileNames: `assets/[name].js`,
|
|
147
|
-
chunkFileNames: `assets/[name].js`,
|
|
148
|
-
assetFileNames: `assets/[name].[ext]`,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
143
|
});
|
|
153
144
|
```
|
|
154
145
|
|
|
@@ -164,15 +155,6 @@ import react from '@vitejs/plugin-react-swc';
|
|
|
164
155
|
// https://vitejs.dev/config/
|
|
165
156
|
export default defineConfig({
|
|
166
157
|
plugins: [react(), vscode()],
|
|
167
|
-
build: {
|
|
168
|
-
rollupOptions: {
|
|
169
|
-
output: {
|
|
170
|
-
entryFileNames: `assets/[name].js`,
|
|
171
|
-
chunkFileNames: `assets/[name].js`,
|
|
172
|
-
assetFileNames: `assets/[name].[ext]`,
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
158
|
});
|
|
177
159
|
```
|
|
178
160
|
|
|
@@ -222,9 +204,17 @@ export default defineConfig({
|
|
|
222
204
|
|
|
223
205
|
`vscode extension` 使用
|
|
224
206
|
|
|
207
|
+
- `development` 模式
|
|
208
|
+
|
|
225
209
|
| 变量 | 描述 |
|
|
226
210
|
| --------------------- | --------------------- |
|
|
227
|
-
| `VITE_DEV_SERVER_URL` |
|
|
211
|
+
| `VITE_DEV_SERVER_URL` | vite开发服务器的url。 |
|
|
212
|
+
|
|
213
|
+
- `production` 模式
|
|
214
|
+
|
|
215
|
+
| 变量 | 描述 |
|
|
216
|
+
| ----------------- | --------------------------------------------------------------- |
|
|
217
|
+
| `VITE_DIST_FILES` | dist目录下的所有js文件,不包括index.js。 它是一个 json 字符串。 |
|
|
228
218
|
|
|
229
219
|
## Debug
|
|
230
220
|
|
|
@@ -298,5 +288,6 @@ pnpm build
|
|
|
298
288
|
|
|
299
289
|
打开 [examples](./examples) 目录,有 `vue` 和 `react` 示例。
|
|
300
290
|
|
|
301
|
-
- [react](./examples/react)
|
|
302
|
-
- [vue](./examples/vue)
|
|
291
|
+
- [react](./examples/react):简单的 react 示例。
|
|
292
|
+
- [vue](./examples/vue):简单的 vue 示例。
|
|
293
|
+
- [vue-import](./examples/vue-import):动态 import() 示例。
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var _tsup = require('tsup');
|
|
|
9
9
|
// src/constants.ts
|
|
10
10
|
var PLUGIN_NAME = "@tomjs:vscode";
|
|
11
11
|
var WEBVIEW_PACKAGE_NAME = "@tomjs/vscode-extension-webview";
|
|
12
|
-
var WEBVIEW_METHOD_NAME = "
|
|
12
|
+
var WEBVIEW_METHOD_NAME = "__getWebviewHtml__";
|
|
13
13
|
|
|
14
14
|
// src/logger.ts
|
|
15
15
|
var _dayjs = require('dayjs'); var _dayjs2 = _interopRequireDefault(_dayjs);
|
|
@@ -146,20 +146,42 @@ function preMergeOptions(options) {
|
|
|
146
146
|
opts.webview = _nullishCoalesce(opts.webview, () => ( WEBVIEW_METHOD_NAME));
|
|
147
147
|
return opts;
|
|
148
148
|
}
|
|
149
|
+
function readAllFiles(dir) {
|
|
150
|
+
return _fs2.default.readdirSync(dir).reduce((files, file) => {
|
|
151
|
+
const name = _path2.default.join(dir, file);
|
|
152
|
+
const isDir = _fs2.default.statSync(name).isDirectory();
|
|
153
|
+
return isDir ? [...files, ...readAllFiles(name)] : [...files, name];
|
|
154
|
+
}, []);
|
|
155
|
+
}
|
|
149
156
|
function useVSCodePlugin(options) {
|
|
150
157
|
const opts = preMergeOptions(options);
|
|
151
158
|
const handleConfig = (config) => {
|
|
152
|
-
var _a, _b;
|
|
159
|
+
var _a, _b, _c, _d, _e;
|
|
153
160
|
let outDir = ((_a = config == null ? void 0 : config.build) == null ? void 0 : _a.outDir) || "dist";
|
|
154
161
|
opts.extension ??= {};
|
|
155
162
|
if (opts.recommended) {
|
|
156
163
|
opts.extension.outDir = _path2.default.resolve(outDir, "extension");
|
|
157
164
|
outDir = _path2.default.resolve(outDir, "webview");
|
|
158
165
|
}
|
|
166
|
+
const assetsDir = ((_b = config == null ? void 0 : config.build) == null ? void 0 : _b.assetsDir) || "assets";
|
|
167
|
+
const output = {
|
|
168
|
+
chunkFileNames: `${assetsDir}/[name].js`,
|
|
169
|
+
entryFileNames: `${assetsDir}/[name].js`,
|
|
170
|
+
assetFileNames: `${assetsDir}/[name].[ext]`
|
|
171
|
+
};
|
|
172
|
+
let rollupOutput = _nullishCoalesce(((_d = (_c = config == null ? void 0 : config.build) == null ? void 0 : _c.rollupOptions) == null ? void 0 : _d.output), () => ( {}));
|
|
173
|
+
if (Array.isArray(rollupOutput)) {
|
|
174
|
+
rollupOutput.map((s) => Object.assign(s, output));
|
|
175
|
+
} else {
|
|
176
|
+
rollupOutput = Object.assign({}, rollupOutput, output);
|
|
177
|
+
}
|
|
159
178
|
return {
|
|
160
179
|
build: {
|
|
161
180
|
outDir,
|
|
162
|
-
sourcemap: isDev ? true : (
|
|
181
|
+
sourcemap: isDev ? true : (_e = config == null ? void 0 : config.build) == null ? void 0 : _e.sourcemap,
|
|
182
|
+
rollupOptions: {
|
|
183
|
+
output: rollupOutput
|
|
184
|
+
}
|
|
163
185
|
}
|
|
164
186
|
};
|
|
165
187
|
};
|
|
@@ -179,6 +201,7 @@ function useVSCodePlugin(options) {
|
|
|
179
201
|
}
|
|
180
202
|
}
|
|
181
203
|
}
|
|
204
|
+
let buildConfig;
|
|
182
205
|
return [
|
|
183
206
|
{
|
|
184
207
|
name: "@tomjs:vscode",
|
|
@@ -249,8 +272,26 @@ function useVSCodePlugin(options) {
|
|
|
249
272
|
config(config) {
|
|
250
273
|
return handleConfig(config);
|
|
251
274
|
},
|
|
275
|
+
configResolved(config) {
|
|
276
|
+
buildConfig = config;
|
|
277
|
+
},
|
|
252
278
|
closeBundle() {
|
|
253
|
-
|
|
279
|
+
const { outDir } = buildConfig.build;
|
|
280
|
+
const cwd2 = process.cwd();
|
|
281
|
+
const allFiles = readAllFiles(outDir).filter((file) => file.endsWith(".js") && !file.endsWith("index.js")).map((s) => s.replace(cwd2, "").replaceAll("\\", "/").substring(1));
|
|
282
|
+
const { onSuccess: _onSuccess, ...tsupOptions } = opts.extension || {};
|
|
283
|
+
_tsup.build.call(void 0,
|
|
284
|
+
_lodashmerge2.default.call(void 0, tsupOptions, {
|
|
285
|
+
env: {
|
|
286
|
+
VITE_DIST_FILES: JSON.stringify(allFiles)
|
|
287
|
+
},
|
|
288
|
+
async onSuccess() {
|
|
289
|
+
if (typeof _onSuccess === "function") {
|
|
290
|
+
await _onSuccess();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
})
|
|
294
|
+
);
|
|
254
295
|
}
|
|
255
296
|
}
|
|
256
297
|
];
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { build as tsupBuild } from "tsup";
|
|
|
9
9
|
// src/constants.ts
|
|
10
10
|
var PLUGIN_NAME = "@tomjs:vscode";
|
|
11
11
|
var WEBVIEW_PACKAGE_NAME = "@tomjs/vscode-extension-webview";
|
|
12
|
-
var WEBVIEW_METHOD_NAME = "
|
|
12
|
+
var WEBVIEW_METHOD_NAME = "__getWebviewHtml__";
|
|
13
13
|
|
|
14
14
|
// src/logger.ts
|
|
15
15
|
import dayjs from "dayjs";
|
|
@@ -145,20 +145,42 @@ function preMergeOptions(options) {
|
|
|
145
145
|
opts.webview = opts.webview ?? WEBVIEW_METHOD_NAME;
|
|
146
146
|
return opts;
|
|
147
147
|
}
|
|
148
|
+
function readAllFiles(dir) {
|
|
149
|
+
return fs2.readdirSync(dir).reduce((files, file) => {
|
|
150
|
+
const name = path.join(dir, file);
|
|
151
|
+
const isDir = fs2.statSync(name).isDirectory();
|
|
152
|
+
return isDir ? [...files, ...readAllFiles(name)] : [...files, name];
|
|
153
|
+
}, []);
|
|
154
|
+
}
|
|
148
155
|
function useVSCodePlugin(options) {
|
|
149
156
|
const opts = preMergeOptions(options);
|
|
150
157
|
const handleConfig = (config) => {
|
|
151
|
-
var _a, _b;
|
|
158
|
+
var _a, _b, _c, _d, _e;
|
|
152
159
|
let outDir = ((_a = config == null ? void 0 : config.build) == null ? void 0 : _a.outDir) || "dist";
|
|
153
160
|
opts.extension ??= {};
|
|
154
161
|
if (opts.recommended) {
|
|
155
162
|
opts.extension.outDir = path.resolve(outDir, "extension");
|
|
156
163
|
outDir = path.resolve(outDir, "webview");
|
|
157
164
|
}
|
|
165
|
+
const assetsDir = ((_b = config == null ? void 0 : config.build) == null ? void 0 : _b.assetsDir) || "assets";
|
|
166
|
+
const output = {
|
|
167
|
+
chunkFileNames: `${assetsDir}/[name].js`,
|
|
168
|
+
entryFileNames: `${assetsDir}/[name].js`,
|
|
169
|
+
assetFileNames: `${assetsDir}/[name].[ext]`
|
|
170
|
+
};
|
|
171
|
+
let rollupOutput = ((_d = (_c = config == null ? void 0 : config.build) == null ? void 0 : _c.rollupOptions) == null ? void 0 : _d.output) ?? {};
|
|
172
|
+
if (Array.isArray(rollupOutput)) {
|
|
173
|
+
rollupOutput.map((s) => Object.assign(s, output));
|
|
174
|
+
} else {
|
|
175
|
+
rollupOutput = Object.assign({}, rollupOutput, output);
|
|
176
|
+
}
|
|
158
177
|
return {
|
|
159
178
|
build: {
|
|
160
179
|
outDir,
|
|
161
|
-
sourcemap: isDev ? true : (
|
|
180
|
+
sourcemap: isDev ? true : (_e = config == null ? void 0 : config.build) == null ? void 0 : _e.sourcemap,
|
|
181
|
+
rollupOptions: {
|
|
182
|
+
output: rollupOutput
|
|
183
|
+
}
|
|
162
184
|
}
|
|
163
185
|
};
|
|
164
186
|
};
|
|
@@ -178,6 +200,7 @@ function useVSCodePlugin(options) {
|
|
|
178
200
|
}
|
|
179
201
|
}
|
|
180
202
|
}
|
|
203
|
+
let buildConfig;
|
|
181
204
|
return [
|
|
182
205
|
{
|
|
183
206
|
name: "@tomjs:vscode",
|
|
@@ -248,8 +271,26 @@ function useVSCodePlugin(options) {
|
|
|
248
271
|
config(config) {
|
|
249
272
|
return handleConfig(config);
|
|
250
273
|
},
|
|
274
|
+
configResolved(config) {
|
|
275
|
+
buildConfig = config;
|
|
276
|
+
},
|
|
251
277
|
closeBundle() {
|
|
252
|
-
|
|
278
|
+
const { outDir } = buildConfig.build;
|
|
279
|
+
const cwd2 = process.cwd();
|
|
280
|
+
const allFiles = readAllFiles(outDir).filter((file) => file.endsWith(".js") && !file.endsWith("index.js")).map((s) => s.replace(cwd2, "").replaceAll("\\", "/").substring(1));
|
|
281
|
+
const { onSuccess: _onSuccess, ...tsupOptions } = opts.extension || {};
|
|
282
|
+
tsupBuild(
|
|
283
|
+
merge(tsupOptions, {
|
|
284
|
+
env: {
|
|
285
|
+
VITE_DIST_FILES: JSON.stringify(allFiles)
|
|
286
|
+
},
|
|
287
|
+
async onSuccess() {
|
|
288
|
+
if (typeof _onSuccess === "function") {
|
|
289
|
+
await _onSuccess();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
);
|
|
253
294
|
}
|
|
254
295
|
}
|
|
255
296
|
];
|