@tomjs/vite-plugin-vscode 1.1.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 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 __getWebviewHtml({ serverUrl: process.env.VITE_DEV_SERVER_URL });
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
- | Variable | Description |
227
- | --------------------- | -------------------------- |
228
- | `VITE_DEV_SERVER_URL` | The url of the dev server. |
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', 'webview', 'assets', 'index.css']);
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', 'webview', 'assets', 'index.js']);
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 __getWebviewHtml({ serverUrl: process.env.VITE_DEV_SERVER_URL });
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` | Vite 开发服务器的 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 = "__getWebviewHtml";
12
+ var WEBVIEW_METHOD_NAME = "__getWebviewHtml__";
13
13
 
14
14
  // src/logger.ts
15
15
  var _dayjs = require('dayjs'); var _dayjs2 = _interopRequireDefault(_dayjs);
@@ -112,6 +112,7 @@ function preMergeOptions(options) {
112
112
  outDir: "dist-extension",
113
113
  target: ["es2019", "node14"],
114
114
  format: "cjs",
115
+ shims: true,
115
116
  clean: true,
116
117
  dts: false,
117
118
  treeshake: !!isDev,
@@ -145,20 +146,42 @@ function preMergeOptions(options) {
145
146
  opts.webview = _nullishCoalesce(opts.webview, () => ( WEBVIEW_METHOD_NAME));
146
147
  return opts;
147
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
+ }
148
156
  function useVSCodePlugin(options) {
149
157
  const opts = preMergeOptions(options);
150
158
  const handleConfig = (config) => {
151
- var _a, _b;
159
+ var _a, _b, _c, _d, _e;
152
160
  let outDir = ((_a = config == null ? void 0 : config.build) == null ? void 0 : _a.outDir) || "dist";
153
161
  opts.extension ??= {};
154
162
  if (opts.recommended) {
155
163
  opts.extension.outDir = _path2.default.resolve(outDir, "extension");
156
164
  outDir = _path2.default.resolve(outDir, "webview");
157
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
+ }
158
178
  return {
159
179
  build: {
160
180
  outDir,
161
- sourcemap: isDev ? true : (_b = config == null ? void 0 : config.build) == null ? void 0 : _b.sourcemap
181
+ sourcemap: isDev ? true : (_e = config == null ? void 0 : config.build) == null ? void 0 : _e.sourcemap,
182
+ rollupOptions: {
183
+ output: rollupOutput
184
+ }
162
185
  }
163
186
  };
164
187
  };
@@ -178,6 +201,7 @@ function useVSCodePlugin(options) {
178
201
  }
179
202
  }
180
203
  }
204
+ let buildConfig;
181
205
  return [
182
206
  {
183
207
  name: "@tomjs:vscode",
@@ -248,8 +272,26 @@ function useVSCodePlugin(options) {
248
272
  config(config) {
249
273
  return handleConfig(config);
250
274
  },
275
+ configResolved(config) {
276
+ buildConfig = config;
277
+ },
251
278
  closeBundle() {
252
- _tsup.build.call(void 0, opts.extension);
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
+ );
253
295
  }
254
296
  }
255
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 = "__getWebviewHtml";
12
+ var WEBVIEW_METHOD_NAME = "__getWebviewHtml__";
13
13
 
14
14
  // src/logger.ts
15
15
  import dayjs from "dayjs";
@@ -111,6 +111,7 @@ function preMergeOptions(options) {
111
111
  outDir: "dist-extension",
112
112
  target: ["es2019", "node14"],
113
113
  format: "cjs",
114
+ shims: true,
114
115
  clean: true,
115
116
  dts: false,
116
117
  treeshake: !!isDev,
@@ -144,20 +145,42 @@ function preMergeOptions(options) {
144
145
  opts.webview = opts.webview ?? WEBVIEW_METHOD_NAME;
145
146
  return opts;
146
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
+ }
147
155
  function useVSCodePlugin(options) {
148
156
  const opts = preMergeOptions(options);
149
157
  const handleConfig = (config) => {
150
- var _a, _b;
158
+ var _a, _b, _c, _d, _e;
151
159
  let outDir = ((_a = config == null ? void 0 : config.build) == null ? void 0 : _a.outDir) || "dist";
152
160
  opts.extension ??= {};
153
161
  if (opts.recommended) {
154
162
  opts.extension.outDir = path.resolve(outDir, "extension");
155
163
  outDir = path.resolve(outDir, "webview");
156
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
+ }
157
177
  return {
158
178
  build: {
159
179
  outDir,
160
- sourcemap: isDev ? true : (_b = config == null ? void 0 : config.build) == null ? void 0 : _b.sourcemap
180
+ sourcemap: isDev ? true : (_e = config == null ? void 0 : config.build) == null ? void 0 : _e.sourcemap,
181
+ rollupOptions: {
182
+ output: rollupOutput
183
+ }
161
184
  }
162
185
  };
163
186
  };
@@ -177,6 +200,7 @@ function useVSCodePlugin(options) {
177
200
  }
178
201
  }
179
202
  }
203
+ let buildConfig;
180
204
  return [
181
205
  {
182
206
  name: "@tomjs:vscode",
@@ -247,8 +271,26 @@ function useVSCodePlugin(options) {
247
271
  config(config) {
248
272
  return handleConfig(config);
249
273
  },
274
+ configResolved(config) {
275
+ buildConfig = config;
276
+ },
250
277
  closeBundle() {
251
- tsupBuild(opts.extension);
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
+ );
252
294
  }
253
295
  }
254
296
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomjs/vite-plugin-vscode",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "The vite plugin for vscode extension, supports esm and cjs.",
5
5
  "keywords": [
6
6
  "vite",
@@ -41,7 +41,7 @@
41
41
  "url": "git+https://github.com/tomjs/vite-plugin-vscode.git"
42
42
  },
43
43
  "dependencies": {
44
- "@tomjs/vscode-extension-webview": "^1.0.3",
44
+ "@tomjs/vscode-extension-webview": "^1.2.0",
45
45
  "dayjs": "^1.11.10",
46
46
  "kolorist": "^1.8.0",
47
47
  "lodash.clonedeep": "^4.5.0",
@@ -57,7 +57,7 @@
57
57
  "@tomjs/tsconfig": "^1.2.1",
58
58
  "@types/lodash.clonedeep": "^4.5.9",
59
59
  "@types/lodash.merge": "^4.6.9",
60
- "@types/node": "^18.19.3",
60
+ "@types/node": "^18.19.4",
61
61
  "cross-env": "^7.0.3",
62
62
  "eslint": "^8.56.0",
63
63
  "husky": "^8.0.3",
@@ -66,7 +66,7 @@
66
66
  "npm-run-all": "^4.1.5",
67
67
  "prettier": "^3.1.1",
68
68
  "rimraf": "^5.0.5",
69
- "stylelint": "^16.0.2",
69
+ "stylelint": "^16.1.0",
70
70
  "tsx": "^4.7.0",
71
71
  "typescript": "~5.3.3"
72
72
  },