rsbuild-pipe 1.0.3 → 1.0.5

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/.editorconfig ADDED
@@ -0,0 +1,31 @@
1
+ # ↓告诉EditorConfig插件,这是根文件,不用继续往上查找。
2
+ root = true
3
+
4
+ # ↓匹配全部文件。
5
+ [*]
6
+ # ↓使用`utf-8`字符集。
7
+ charset=utf-8
8
+ # ↓结尾换行符,可选`lf`、`cr`、`crlf`。
9
+ end_of_line=lf
10
+ # ↓在文件结尾插入新行。
11
+ insert_final_newline=true
12
+ # ↓缩进的样式为空格。
13
+ indent_style=space
14
+ # ↓缩进为2。
15
+ indent_size=2
16
+ # ↓行最大长度为100。
17
+ max_line_length = 100
18
+
19
+ # ↓匹配以`.yml`、`.yaml`、`.json`结尾的文件。
20
+ [*.{yml,yaml,json}]
21
+ indent_style = space
22
+ indent_size = 2
23
+
24
+ # ↓匹配以`.md`结尾的文件。
25
+ [*.md]
26
+ # ↓
27
+ trim_trailing_whitespace = false
28
+
29
+ [Makefile]
30
+ indent_style = tab
31
+
package/README.md CHANGED
@@ -3,7 +3,15 @@
3
3
  rsbuild开发和打包管道
4
4
 
5
5
  ## Change Log
6
- v1.0.0
6
+
7
+ ### v1.0.5
8
+ ```
9
+ upgrade rsbuild version 0.7.10
10
+
11
+ 将rsbuild.extend.config.ts中的getCesiumEngineConfig改成getNodePolyfillConfig
7
12
  ```
8
13
 
14
+ ### v1.0.4
15
+ ```
16
+ upgrade rsbuild version 0.7.9
9
17
  ```
@@ -1,10 +1,10 @@
1
1
  import { mergeRsbuildConfig, type RsbuildConfig } from '@rsbuild/core';
2
2
  import { pluginReact, type PluginReactOptions } from '@rsbuild/plugin-react';
3
- import { pluginSvgr, PluginSvgrOptions } from "@rsbuild/plugin-svgr";
4
- import { pluginSass, PluginSassOptions } from "@rsbuild/plugin-sass";
5
- import { pluginLess, PluginLessOptions } from "@rsbuild/plugin-less";
6
- import { pluginTypeCheck, PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check';
7
- import { pluginBasicSsl } from '@rsbuild/plugin-basic-ssl';
3
+ import { pluginSvgr, type PluginSvgrOptions } from "@rsbuild/plugin-svgr";
4
+ import { pluginSass, type PluginSassOptions } from "@rsbuild/plugin-sass";
5
+ import { pluginLess, type PluginLessOptions } from "@rsbuild/plugin-less";
6
+ import { pluginTypeCheck, type PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check';
7
+ import { pluginBasicSsl, type PluginBasicSslOptions } from '@rsbuild/plugin-basic-ssl';
8
8
 
9
9
  export * as helper from "./helper";
10
10
  export * from "@rsbuild/core";
@@ -20,6 +20,7 @@ export const isProd = process.env.NODE_ENV === 'production'; // 是否为生成
20
20
  interface GetBaseConfigParams {
21
21
  rsbuildConfig?: RsbuildConfig,
22
22
  pluginBasicSslEnable?: boolean, // 是否使用插件: @rsbuild/plugin-basic-ssl
23
+ pluginBasicSslOptions?: PluginBasicSslOptions,
23
24
  pluginReactEnable?: boolean, // 是否使用插件: @rsbuild/plugin-react
24
25
  pluginReactOptions?: PluginReactOptions,
25
26
  pluginSvgrEnable?: boolean, // 是否使用插件: @rsbuild/plugin-svgr
@@ -36,6 +37,7 @@ export const getBaseConfig = (params: GetBaseConfigParams = {}):RsbuildConfig =>
36
37
  const {
37
38
  rsbuildConfig = {},
38
39
  pluginBasicSslEnable = false,
40
+ pluginBasicSslOptions = {},
39
41
  pluginReactEnable = true,
40
42
  pluginReactOptions = {},
41
43
  pluginSvgrEnable = true,
@@ -107,7 +109,7 @@ export const getBaseConfig = (params: GetBaseConfigParams = {}):RsbuildConfig =>
107
109
  pluginLessEnable ? pluginLess(pluginLessOptions) : null,
108
110
 
109
111
  // 是否使用自签名的https证书
110
- pluginBasicSslEnable ? pluginBasicSsl() : null,
112
+ pluginBasicSslEnable ? pluginBasicSsl(pluginBasicSslOptions) : null,
111
113
  ],
112
114
  }, rsbuildConfig);
113
115
  }
@@ -1,7 +1,7 @@
1
- import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
2
- import { pluginBabel, PluginBabelOptions } from '@rsbuild/plugin-babel';
1
+ import { pluginNodePolyfill, type PluginNodePolyfillOptions } from '@rsbuild/plugin-node-polyfill';
2
+ import { pluginBabel, type PluginBabelOptions } from '@rsbuild/plugin-babel';
3
3
 
4
- import { isProd, helper, type RsbuildConfig } from './rsbuild.base.config';
4
+ import { isProd, helper, deepmerge, type RsbuildConfig } from './rsbuild.base.config';
5
5
  const path = require("path");
6
6
  const fs = require("fs");
7
7
 
@@ -43,29 +43,60 @@ export const getBabelConfig = (params: GetBabelConfigParams = {}): RsbuildConfig
43
43
  }
44
44
  }
45
45
 
46
+ interface GetNodePolyfillParams {
47
+ nodePolyfillOptions?: PluginNodePolyfillOptions,
48
+ cesiumEngine?: {
49
+ enable?: boolean, // 是否开启cesium配置
50
+ options: {
51
+ srcDirPath: string, // cesium engine的基础目录路基
52
+ distDirPath: string, // 目标路径
53
+ modifyCodeEnable?: boolean, // 是否允许修改源代码
54
+ }
55
+ }
56
+ }
57
+
46
58
  /**
47
- * 配置cesium engine
59
+ * 配置node-polyfill
48
60
  */
49
- export const getCesiumEngineConfig = ({ srcDirPath, distDirPath, modifyCodeEnable = true }: {
50
- srcDirPath: string, // cesium engine的基础目录路基
51
- distDirPath: string, // 目标路径
52
- modifyCodeEnable?: boolean, // 是否允许修改源代码
53
- }): RsbuildConfig => {
54
- // const cesiumEngineBase = '../vendor/node_modules/@cesium/engine'; // cesium engine的源码目录
55
- // const distDir = "static"; // 目标目录
61
+ export const getNodePolyfillConfig = ({nodePolyfillOptions = {}, cesiumEngine }: GetNodePolyfillParams): RsbuildConfig => {
62
+ const config: RsbuildConfig = {};
63
+
64
+ // 配置cesiumEngine
65
+ if (cesiumEngine) {
66
+ const { enable = true, options } = cesiumEngine;
67
+
68
+ if (enable) {
69
+ const { srcDirPath, distDirPath, modifyCodeEnable = true } = options;
70
+ config.output = {
71
+ copy: [
72
+ // { from: path.join(srcDirPath, 'Build/Workers'), to: distDirPath+'/Workers' },
73
+ { from: path.join(srcDirPath, 'Source/Assets'), to: distDirPath + '/Assets' },
74
+ { from: path.join(srcDirPath, 'Build/ThirdParty'), to: distDirPath + '/ThirdParty' },
75
+ ],
76
+ }
56
77
 
57
- const config: RsbuildConfig = {
58
- output: {
59
- copy: [
60
- // { from: path.join(srcDirPath, 'Build/Workers'), to: distDirPath+'/Workers' },
61
- { from: path.join(srcDirPath, 'Source/Assets'), to: distDirPath + '/Assets' },
62
- { from: path.join(srcDirPath, 'Build/ThirdParty'), to: distDirPath + '/ThirdParty' },
63
- ],
64
- },
65
- plugins: [
66
- pluginNodePolyfill({
78
+ config.tools = {
79
+ rspack: {
80
+ // 注意: rsbuild编译代码时import.meta不支持,暂时将import.meta替换成'{}'空对象
81
+ // plugins: [
82
+ // new rspack.DefinePlugin({
83
+ // 'import.meta': '{}'
84
+ // })
85
+ // ],
86
+ module: {
87
+ rules: [
88
+ // 添加.glsl文件转为字符串
89
+ {
90
+ test: /\.glsl$/,
91
+ type: 'asset/source',
92
+ },
93
+ ]
94
+ }
95
+ }
96
+ }
97
+
98
+ nodePolyfillOptions = deepmerge(nodePolyfillOptions, {
67
99
  globals: {
68
- // @ts-ignore
69
100
  https: false,
70
101
  http: false,
71
102
  zlib: false,
@@ -76,94 +107,77 @@ export const getCesiumEngineConfig = ({ srcDirPath, distDirPath, modifyCodeEnabl
76
107
  stream: false,
77
108
  }
78
109
  })
79
- ],
80
110
 
81
- tools: {
82
- rspack: {
83
- // 注意: rsbuild编译代码时import.meta不支持,暂时将import.meta替换成'{}'空对象
84
- // plugins: [
85
- // new rspack.DefinePlugin({
86
- // 'import.meta': '{}'
87
- // })
88
- // ],
89
- module: {
90
- rules: [
91
- // 添加.glsl文件转为字符串
92
- {
93
- test: /\.glsl$/,
94
- type: 'asset/source',
95
- },
96
- ]
111
+
112
+ if (modifyCodeEnable) {
113
+ //***********************************修改源码start****************************************
114
+ /*
115
+ //d frontToBack添加try catch的原因, 调用Cesium.DrawCommand并传入Cesium.PASS.TRANSLUCENT(半透明物体)时,在监听点击或鼠标移动事件等时, 会报错: TypeError: Cannot read properties of undefined (reading 'distanceSquaredTo')
116
+ // 这样会影响程序的运行,所以暂时添加try catch来抑制异常的抛出
117
+ new Cesium.DrawCommand({
118
+ ...
119
+ ...
120
+ pass: Cesium.PASS.TRANSLUCENT,
121
+ });
122
+ */
123
+ const fs = require('fs');
124
+ const srcFilePath = `${srcDirPath}/Source/Scene/Scene.js`;
125
+ const data = fs.readFileSync(srcFilePath, 'utf-8');
126
+ const replaced = data.replace(`function frontToBack(a, b, position) {
127
+ // When distances are equal equal favor sorting b before a. This gives render priority to commands later in the list.
128
+ return (
129
+ a.boundingVolume.distanceSquaredTo(position) -
130
+ b.boundingVolume.distanceSquaredTo(position) +
131
+ CesiumMath.EPSILON12
132
+ );
133
+ }`, `function frontToBack(a, b, position) {
134
+ // When distances are equal equal favor sorting b before a. This gives render priority to commands later in the list.
135
+ try{
136
+ return (
137
+ a.boundingVolume.distanceSquaredTo(position) -
138
+ b.boundingVolume.distanceSquaredTo(position) +
139
+ CesiumMath.EPSILON12
140
+ );
141
+ }catch(e){
142
+
143
+ }
144
+ }`);
145
+
146
+ fs.writeFileSync(srcFilePath, replaced, 'utf-8')
147
+ }
148
+
149
+
150
+ // TODO: 开发环境下copy Build/Workers正常,生成环境下打包copy Build/Workers会报如下错误:
151
+ // × JavaScript parsing error: 'import', and 'export' cannot be used outside of module code
152
+ // ╭─[24:1]
153
+ // 24 │ */
154
+ // 25 │
155
+ // 26 │ import {
156
+ // · ──────
157
+ // 27 │ defined_default
158
+ // 28 │ } from "./chunk-YBKFS53K.js";
159
+ // ╰────
160
+ // 所以在生成环境下打包不器用copy Build/Workers, 而是采用打包换成后再将Build/Workers放到指定目录中,
161
+ // copy过程暂时发到package.json scripts build命令中了,请参照
162
+
163
+ if (!isProd) {
164
+ if (config.output?.copy) {
165
+ (config.output?.copy as any[]).push({
166
+ from: path.join(srcDirPath, 'Build/Workers'), to: distDirPath + '/Workers'
167
+ })
97
168
  }
169
+ } else {
170
+ setTimeout(() => {
171
+ const dist = path.join(path.resolve('./'), "dist/" + distDirPath + "/Workers");
172
+ if (!fs.existsSync(dist)) fs.mkdirSync(dist, { recursive: true });
173
+ helper.copy(path.join(srcDirPath, 'Build/Workers'), dist)
174
+ }, 3000)
98
175
  }
99
- },
100
- }
101
-
102
-
103
- if (modifyCodeEnable) {
104
- //***********************************修改源码start****************************************
105
- /*
106
- //d frontToBack添加try catch的原因, 调用Cesium.DrawCommand并传入Cesium.PASS.TRANSLUCENT(半透明物体)时,在监听点击或鼠标移动事件等时, 会报错: TypeError: Cannot read properties of undefined (reading 'distanceSquaredTo')
107
- // 这样会影响程序的运行,所以暂时添加try catch来抑制异常的抛出
108
- new Cesium.DrawCommand({
109
- ...
110
- ...
111
- pass: Cesium.PASS.TRANSLUCENT,
112
- });
113
- */
114
- const fs = require('fs');
115
- const srcFilePath = `${srcDirPath}/Source/Scene/Scene.js`;
116
- const data = fs.readFileSync(srcFilePath, 'utf-8');
117
- const replaced = data.replace(`function frontToBack(a, b, position) {
118
- // When distances are equal equal favor sorting b before a. This gives render priority to commands later in the list.
119
- return (
120
- a.boundingVolume.distanceSquaredTo(position) -
121
- b.boundingVolume.distanceSquaredTo(position) +
122
- CesiumMath.EPSILON12
123
- );
124
- }`, `function frontToBack(a, b, position) {
125
- // When distances are equal equal favor sorting b before a. This gives render priority to commands later in the list.
126
- try{
127
- return (
128
- a.boundingVolume.distanceSquaredTo(position) -
129
- b.boundingVolume.distanceSquaredTo(position) +
130
- CesiumMath.EPSILON12
131
- );
132
- }catch(e){
133
-
134
- }
135
- }`);
136
-
137
- fs.writeFileSync(srcFilePath, replaced, 'utf-8')
138
- }
139
-
140
-
141
- // TODO: 开发环境下copy Build/Workers正常,生成环境下打包copy Build/Workers会报如下错误:
142
- // × JavaScript parsing error: 'import', and 'export' cannot be used outside of module code
143
- // ╭─[24:1]
144
- // 24 │ */
145
- // 25 │
146
- // 26 │ import {
147
- // · ──────
148
- // 27 │ defined_default
149
- // 28 │ } from "./chunk-YBKFS53K.js";
150
- // ╰────
151
- // 所以在生成环境下打包不器用copy Build/Workers, 而是采用打包换成后再将Build/Workers放到指定目录中,
152
- // copy过程暂时发到package.json scripts build命令中了,请参照
153
-
154
- if (!isProd) {
155
- if (config.output?.copy) {
156
- (config.output?.copy as any[]).push({
157
- from: path.join(srcDirPath, 'Build/Workers'), to: distDirPath + '/Workers'
158
- })
159
176
  }
160
- } else {
161
- setTimeout(() => {
162
- const dist = path.join(path.resolve('./'), "dist/" + distDirPath + "/Workers");
163
- if (!fs.existsSync(dist)) fs.mkdirSync(dist, { recursive: true });
164
- helper.copy(path.join(srcDirPath, 'Build/Workers'), dist)
165
- }, 3000)
166
177
  }
167
178
 
179
+ // 添加node-polyfill插件
180
+ config.plugins = [pluginNodePolyfill(nodePolyfillOptions)]
181
+
168
182
  return config;
169
183
  }
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "rsbuild-pipe",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "author": "chencheng <daniel_txy@163.com>",
5
5
  "description": "rsbuild pipe",
6
6
  "main": "index",
7
7
  "dependencies": {
8
- "@rsbuild/core": "0.7.6",
9
- "@rsbuild/plugin-babel": "0.7.6",
10
- "@rsbuild/plugin-basic-ssl": "0.7.6",
11
- "@rsbuild/plugin-less": "0.7.6",
12
- "@rsbuild/plugin-node-polyfill": "0.7.6",
13
- "@rsbuild/plugin-react": "0.7.6",
14
- "@rsbuild/plugin-sass": "0.7.6",
15
- "@rsbuild/plugin-svgr": "0.7.6",
16
- "@rsbuild/plugin-type-check": "0.7.6",
17
- "@types/node": "20.14.2",
8
+ "@rsbuild/core": "0.7.10",
9
+ "@rsbuild/plugin-babel": "0.7.10",
10
+ "@rsbuild/plugin-basic-ssl": "0.7.10",
11
+ "@rsbuild/plugin-less": "0.7.10",
12
+ "@rsbuild/plugin-node-polyfill": "0.7.10",
13
+ "@rsbuild/plugin-react": "0.7.10",
14
+ "@rsbuild/plugin-sass": "0.7.10",
15
+ "@rsbuild/plugin-svgr": "0.7.10",
16
+ "@rsbuild/plugin-type-check": "0.7.10",
17
+ "@types/node": "20.14.11",
18
18
  "deepmerge": "4.3.1",
19
- "sass": "^1.77.5"
19
+ "sass": "1.77.8"
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",