@lynx-js/template-webpack-plugin-canary 0.6.11 → 0.6.12-canary-20250521-8299f907

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @lynx-js/template-webpack-plugin
2
2
 
3
+ ## 0.6.12-canary-20250521142037-8299f907d3a2cf7387da98cc4fb2729cc39c4d98
4
+
5
+ ### Patch Changes
6
+
7
+ - Support `output.inlineScripts`, which controls whether to inline scripts into Lynx bundle (`.lynx.bundle`). ([#874](https://github.com/lynx-family/lynx-stack/pull/874))
8
+
9
+ Only background thread scripts can remain non-inlined, whereas the main thread script is always inlined.
10
+
11
+ example:
12
+
13
+ ```js
14
+ import { defineConfig } from "@lynx-js/rspeedy";
15
+
16
+ export default defineConfig({
17
+ output: {
18
+ inlineScripts: false,
19
+ },
20
+ });
21
+ ```
22
+
3
23
  ## 0.6.11
4
24
 
5
25
  ### Patch Changes
@@ -73,7 +93,7 @@
73
93
  - Add `defaultOverflowVisible` option to `LynxTemplatePlugin`. ([#78](https://github.com/lynx-family/lynx-stack/pull/78))
74
94
 
75
95
  ```js
76
- import { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin';
96
+ import { LynxTemplatePlugin } from "@lynx-js/template-webpack-plugin";
77
97
 
78
98
  new LynxTemplatePlugin({
79
99
  defaultOverflowVisible: false,
@@ -92,10 +112,10 @@
92
112
  - 1abf8f0: Add `entryNames` parameter to `beforeEncode` hook.
93
113
 
94
114
  ```js
95
- import { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin';
115
+ import { LynxTemplatePlugin } from "@lynx-js/template-webpack-plugin";
96
116
 
97
117
  const hooks = LynxTemplatePlugin.getLynxTemplatePluginHooks(compilation);
98
- hooks.beforeEncode.tap('MyPlugin', ({ entryNames }) => {
118
+ hooks.beforeEncode.tap("MyPlugin", ({ entryNames }) => {
99
119
  console.log(entryNames);
100
120
  });
101
121
  ```
@@ -7,6 +7,8 @@ import type { CSS } from './index.js';
7
7
  * @public
8
8
  */
9
9
  export interface LynxEncodePluginOptions {
10
+ encodeBinary?: string;
11
+ inlineScripts?: boolean;
10
12
  }
11
13
  /**
12
14
  * LynxEncodePlugin
@@ -72,6 +72,7 @@ export class LynxEncodePlugin {
72
72
  static defaultOptions = Object
73
73
  .freeze({
74
74
  encodeBinary: 'napi',
75
+ inlineScripts: true,
75
76
  });
76
77
  /**
77
78
  * The entry point of a webpack plugin.
@@ -109,6 +110,15 @@ export class LynxEncodePluginImpl {
109
110
  }, async (args) => {
110
111
  const { encodeData } = args;
111
112
  const { manifest } = encodeData;
113
+ let publicPath = '/';
114
+ if (!this.options.inlineScripts) {
115
+ if (typeof compilation?.outputOptions.publicPath === 'function') {
116
+ compilation.errors.push(new compiler.webpack.WebpackError('`publicPath` as a function is not supported yet.'));
117
+ }
118
+ else {
119
+ publicPath = compilation?.outputOptions.publicPath ?? '/';
120
+ }
121
+ }
112
122
  if (!isDebug() && !isDev && !isRsdoctor()) {
113
123
  [
114
124
  encodeData.lepusCode.root,
@@ -138,14 +148,16 @@ export class LynxEncodePluginImpl {
138
148
  '/app-service.js': [
139
149
  this.#appServiceBanner(),
140
150
  Object.keys(manifest)
141
- .map((name) => `module.exports=lynx.requireModule('${this.#formatJSName(name)}',globDynamicComponentEntry?globDynamicComponentEntry:'__Card__')`)
151
+ .map((name) => `module.exports=lynx.requireModule('${this.#formatJSName(name, publicPath)}',globDynamicComponentEntry?globDynamicComponentEntry:'__Card__')`)
142
152
  .join(','),
143
153
  this.#appServiceFooter(),
144
154
  ].join(''),
145
- ...(Object.fromEntries(Object.entries(manifest).map(([name, source]) => [
146
- this.#formatJSName(name),
147
- source,
148
- ]))),
155
+ ...(this.options.inlineScripts
156
+ ? Object.fromEntries(Object.entries(manifest).map(([name, source]) => [
157
+ this.#formatJSName(name, publicPath),
158
+ source,
159
+ ]))
160
+ : {}),
149
161
  };
150
162
  return args;
151
163
  });
@@ -172,8 +184,8 @@ export class LynxEncodePluginImpl {
172
184
  const amdFooter = `});return tt.require('${this.#APP_SERVICE_NAME}');`;
173
185
  return amdFooter + loadScriptFooter;
174
186
  }
175
- #formatJSName(name) {
176
- return `/${name}`;
187
+ #formatJSName(name, publicPath) {
188
+ return publicPath + name;
177
189
  }
178
190
  options;
179
191
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/template-webpack-plugin-canary",
3
- "version": "0.6.11",
3
+ "version": "0.6.12-canary-20250521-8299f907",
4
4
  "description": "Simplifies creation of Lynx template files to serve your webpack bundles",
5
5
  "keywords": [
6
6
  "webpack",
@@ -43,7 +43,7 @@
43
43
  "@microsoft/api-extractor": "7.52.8",
44
44
  "@types/css-tree": "^2.3.10",
45
45
  "@types/object.groupby": "^1.0.4",
46
- "webpack": "^5.99.8",
46
+ "webpack": "^5.99.9",
47
47
  "@lynx-js/test-tools": "0.0.0",
48
48
  "@lynx-js/vitest-setup": "0.0.0"
49
49
  },