xshell 1.2.17 → 1.2.18

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.
Files changed (3) hide show
  1. package/builder.d.ts +17 -1
  2. package/builder.js +22 -3
  3. package/package.json +1 -1
package/builder.d.ts CHANGED
@@ -48,6 +48,10 @@ export interface HtmlOptions {
48
48
  heads?: string[];
49
49
  notice?: boolean;
50
50
  }
51
+ export interface SingleJsConfig {
52
+ js: string;
53
+ entry: string;
54
+ }
51
55
  interface AssetOption {
52
56
  /** 相对 fpd_root 的路径,或者绝对路径 */
53
57
  src: string;
@@ -82,6 +86,10 @@ export interface BundlerOptions {
82
86
  template?: boolean;
83
87
  license?: boolean;
84
88
  htmls?: Record<string, HtmlOptions>;
89
+ single_js?: {
90
+ js: string;
91
+ entry: string;
92
+ };
85
93
  }
86
94
  export declare class Bundler {
87
95
  name: string;
@@ -97,6 +105,7 @@ export declare class Bundler {
97
105
  assets?: Assets;
98
106
  assets_root: string;
99
107
  template: boolean;
108
+ single_js?: BundlerOptions['single_js'];
100
109
  globals?: BundlerOptions['globals'];
101
110
  exclude_modules?: BundlerOptions['exclude_modules'];
102
111
  license?: boolean;
@@ -121,6 +130,9 @@ export declare class Bundler {
121
130
  启用后 assets, html 中的 icon, scripts 路径直接在前面添加 assets_root 来生成最终 html href
122
131
  未启用时使用相对 html 路径来生成最终 html href
123
132
  - template?: `false` 除了生成对应的 html 之外,还生成所有路径为 `{root}/...` 的模板 html 文件, 方便后续 server 替换渲染
133
+ - single_js?: 设置生成的单个 js 入口文件,无其他依赖,通过 script module 作为入口加载,含有 import 加载其他 externals 和某个 entry,类似 htmls 配置要生成的 html
134
+ - js: js 入口文件名
135
+ - entry: 使用的 entry
124
136
  - local_loaders?: `true` true 时使用项目 node_modules/ 中的 loader; false 时使用 D:/0/ 下面的
125
137
  - commonjs2?: `false` 打包为 commonjs2 (.cjs) 的文件
126
138
  - expose?: `false` 入口模块所有导出的属性赋值到全局对象 globalThis 上
@@ -136,7 +148,7 @@ export declare class Bundler {
136
148
  - production?: `true` webpack mode 设置为 'production'
137
149
  - sass?: 传入 sass 实例避免 webpack 重复加载 .cjs 版本
138
150
  - license?: 使用 license-webpack-plugin 构建 ThirdPartyNotice.txt */
139
- constructor(name: string, target: 'web' | 'nodejs', fpd_root: string, fpd_out: string, fpdt_cache: string, entry: Record<string, string>, { source_map, globals, external_dayjs, externals, htmls, assets, assets_root, template, commonjs2, expose, single_chunk, dynamic_import, resolve_alias, resolve_fallback, assets_stats, analyzer, dts, exclude_modules, cache_version, production, sass, dependencies, license, }?: BundlerOptions);
151
+ constructor(name: string, target: 'web' | 'nodejs', fpd_root: string, fpd_out: string, fpdt_cache: string, entry: Record<string, string>, { source_map, globals, external_dayjs, externals, htmls, assets, assets_root, template, single_js, commonjs2, expose, single_chunk, dynamic_import, resolve_alias, resolve_fallback, assets_stats, analyzer, dts, exclude_modules, cache_version, production, sass, dependencies, license, }?: BundlerOptions);
140
152
  build(print?: boolean): Promise<void>;
141
153
  close(): Promise<void>;
142
154
  build_all(print?: boolean): Promise<void>;
@@ -148,6 +160,10 @@ export declare class Bundler {
148
160
  info: boolean;
149
161
  files: boolean;
150
162
  }): Promise<void>;
163
+ build_single_js(print?: {
164
+ info: boolean;
165
+ files: boolean;
166
+ }): Promise<void>;
151
167
  resolve_dependencies(dependency_ids: DependencyId[], resolveds?: Set<DependencyId>): Set<DependencyId>;
152
168
  /** 解析依赖的文件
153
169
  - dependencies: 依赖 id
package/builder.js CHANGED
@@ -137,6 +137,7 @@ export class Bundler {
137
137
  assets;
138
138
  assets_root;
139
139
  template;
140
+ single_js;
140
141
  globals;
141
142
  exclude_modules;
142
143
  license;
@@ -161,6 +162,9 @@ export class Bundler {
161
162
  启用后 assets, html 中的 icon, scripts 路径直接在前面添加 assets_root 来生成最终 html href
162
163
  未启用时使用相对 html 路径来生成最终 html href
163
164
  - template?: `false` 除了生成对应的 html 之外,还生成所有路径为 `{root}/...` 的模板 html 文件, 方便后续 server 替换渲染
165
+ - single_js?: 设置生成的单个 js 入口文件,无其他依赖,通过 script module 作为入口加载,含有 import 加载其他 externals 和某个 entry,类似 htmls 配置要生成的 html
166
+ - js: js 入口文件名
167
+ - entry: 使用的 entry
164
168
  - local_loaders?: `true` true 时使用项目 node_modules/ 中的 loader; false 时使用 D:/0/ 下面的
165
169
  - commonjs2?: `false` 打包为 commonjs2 (.cjs) 的文件
166
170
  - expose?: `false` 入口模块所有导出的属性赋值到全局对象 globalThis 上
@@ -176,7 +180,7 @@ export class Bundler {
176
180
  - production?: `true` webpack mode 设置为 'production'
177
181
  - sass?: 传入 sass 实例避免 webpack 重复加载 .cjs 版本
178
182
  - license?: 使用 license-webpack-plugin 构建 ThirdPartyNotice.txt */
179
- constructor(name, target, fpd_root, fpd_out, fpdt_cache, entry, { source_map = true, globals, external_dayjs = false, externals, htmls, assets, assets_root = '/', template = false, commonjs2 = false, expose = false, single_chunk = true, dynamic_import = true, resolve_alias, resolve_fallback, assets_stats = true, analyzer = false, dts = false, exclude_modules, cache_version, production = true, sass, dependencies, license, } = {}) {
183
+ constructor(name, target, fpd_root, fpd_out, fpdt_cache, entry, { source_map = true, globals, external_dayjs = false, externals, htmls, assets, assets_root = '/', template = false, single_js, commonjs2 = false, expose = false, single_chunk = true, dynamic_import = true, resolve_alias, resolve_fallback, assets_stats = true, analyzer = false, dts = false, exclude_modules, cache_version, production = true, sass, dependencies, license, } = {}) {
180
184
  this.name = name;
181
185
  this.analyzer = analyzer;
182
186
  this.production = production;
@@ -188,6 +192,7 @@ export class Bundler {
188
192
  this.assets = assets;
189
193
  this.assets_root = assets_root;
190
194
  this.template = template;
195
+ this.single_js = single_js;
191
196
  this.globals = globals;
192
197
  this.exclude_modules = exclude_modules;
193
198
  if (dependencies) {
@@ -499,7 +504,8 @@ export class Bundler {
499
504
  await Promise.all([
500
505
  this.build(print),
501
506
  this.copy_files({ print: { info: print, files: false } }),
502
- this.target === 'web' && this.htmls && this.build_htmls({ info: print, files: false })
507
+ this.target === 'web' && this.htmls && this.build_htmls({ info: print, files: false }),
508
+ this.target === 'web' && this.single_js && this.build_single_js({ info: print, files: false })
503
509
  ]);
504
510
  }
505
511
  /** 打包构建 js, 构建 html, 复制依赖文件 */
@@ -507,7 +513,8 @@ export class Bundler {
507
513
  await Promise.all([
508
514
  this.build_and_close(print),
509
515
  this.copy_files({ print: { info: print, files: false } }),
510
- this.target === 'web' && this.htmls && this.build_htmls({ info: print, files: false })
516
+ this.target === 'web' && this.htmls && this.build_htmls({ info: print, files: false }),
517
+ this.target === 'web' && this.single_js && this.build_single_js({ info: print, files: false })
511
518
  ]);
512
519
  }
513
520
  /** 仅打包构建 js, 不复制依赖 */
@@ -558,6 +565,18 @@ export class Bundler {
558
565
  if (print.files)
559
566
  console.log(`${this.name} 的所有 html 页面构建完成`);
560
567
  }
568
+ async build_single_js(print = { info: true, files: false }) {
569
+ const { js, entry } = this.single_js;
570
+ await fwrite(`${this.fpd_out}${js}`, [
571
+ ...this.resolve_dependency_assets(this.dependencies, false, { production: this.production })
572
+ .map(asset => get_vendor_asset_out(asset)),
573
+ entry
574
+ ]
575
+ .map(script => `import from '${this.assets_root}${script}'`)
576
+ .join_lines(), noprint);
577
+ if (print.files)
578
+ console.log(`${this.name} 的入口 ${js} 构建完成`);
579
+ }
561
580
  resolve_dependencies(dependency_ids, resolveds = new Set()) {
562
581
  dependency_ids.forEach(id => {
563
582
  if (!resolveds.has(id)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.2.17",
3
+ "version": "1.2.18",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {