rsbuild-pipe 1.0.0 → 1.0.2

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.
@@ -1,6 +1,8 @@
1
1
  import { mergeRsbuildConfig, type RsbuildConfig } from '@rsbuild/core';
2
2
  import { pluginReact, type PluginReactOptions } from '@rsbuild/plugin-react';
3
3
  import { pluginSvgr, PluginSvgrOptions } from "@rsbuild/plugin-svgr";
4
+ import { pluginSass, PluginSassOptions } from "@rsbuild/plugin-sass";
5
+ import { pluginLess, PluginLessOptions } from "@rsbuild/plugin-less";
4
6
  import { pluginTypeCheck, PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check';
5
7
  import { pluginBasicSsl } from '@rsbuild/plugin-basic-ssl';
6
8
 
@@ -22,6 +24,10 @@ interface GetBaseConfigParams {
22
24
  pluginReactOptions?: PluginReactOptions,
23
25
  pluginSvgrEnable?: boolean, // 是否使用插件: @rsbuild/plugin-svgr
24
26
  pluginSvgrOptions?: PluginSvgrOptions,
27
+ pluginSassEnable?: boolean, // 是否使用插件: @rsbuild/plugin-sass
28
+ pluginSassOptions?: PluginSassOptions,
29
+ pluginLessEnable?: boolean, // 是否使用插件: @rsbuild/plugin-less
30
+ pluginLessOptions?: PluginLessOptions,
25
31
  pluginTypeCheckEnable?: boolean, // 是否使用插件: @rsbuild/plugin-type-check
26
32
  pluginTypeCheckerOptions?: PluginTypeCheckerOptions,
27
33
  };
@@ -34,6 +40,10 @@ export const getBaseConfig = (params: GetBaseConfigParams = {}):RsbuildConfig =>
34
40
  pluginReactOptions = {},
35
41
  pluginSvgrEnable = true,
36
42
  pluginSvgrOptions = {},
43
+ pluginSassEnable = true,
44
+ pluginSassOptions = {},
45
+ pluginLessEnable = true,
46
+ pluginLessOptions = {},
37
47
  pluginTypeCheckEnable = true,
38
48
  pluginTypeCheckerOptions = {},
39
49
  } = params;
@@ -74,7 +84,7 @@ export const getBaseConfig = (params: GetBaseConfigParams = {}):RsbuildConfig =>
74
84
  // react插件true
75
85
  pluginReactEnable ? pluginReact(pluginReactOptions) : null,
76
86
 
77
- // typescript 语法检查,注意语法错误只能在命令行中输出,不能再页面中输出
87
+ // typescript 语法检查,注意语法错误只能在命令行中输出,不能支持less,scss再页面中输出
78
88
  pluginTypeCheckEnable ? pluginTypeCheck(deepmerge({
79
89
  forkTsCheckerOptions: {
80
90
  async: true,
@@ -90,6 +100,12 @@ export const getBaseConfig = (params: GetBaseConfigParams = {}):RsbuildConfig =>
90
100
  mixedImport: true,
91
101
  }, pluginSvgrOptions)) : null,
92
102
 
103
+ // 支持sass,scss
104
+ pluginSassEnable ? pluginSass(pluginSassOptions) : null,
105
+
106
+ // 支持less
107
+ pluginLessEnable ? pluginLess(pluginLessOptions) : null,
108
+
93
109
  // 是否使用自签名的https证书
94
110
  pluginBasicSslEnable ? pluginBasicSsl() : null,
95
111
  ],
@@ -1,21 +1,21 @@
1
1
  import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
2
2
  import { pluginBabel, PluginBabelOptions } from '@rsbuild/plugin-babel';
3
3
 
4
- import { isProd, rspack, helper, type RsbuildConfig } from './rsbuild.base.config';
4
+ import { isProd, helper, type RsbuildConfig } from './rsbuild.base.config';
5
5
  const path = require("path");
6
6
  const fs = require("fs");
7
7
 
8
- interface GetBabelConfigParams{
8
+ interface GetBabelConfigParams {
9
9
  styledJsxEnabled?: boolean,
10
- modifyConfig?:(config:PluginBabelOptions["babelLoaderOptions"]) => PluginBabelOptions["babelLoaderOptions"],
10
+ modifyConfig?: (config: PluginBabelOptions["babelLoaderOptions"]) => PluginBabelOptions["babelLoaderOptions"],
11
11
  }
12
12
 
13
13
  /**
14
14
  * 参数文档配置: https://rsbuild.dev/zh/plugins/list/plugin-babel
15
15
  * 获取babel配置
16
16
  */
17
- export const getBabelConfig = (params:GetBabelConfigParams = {}): RsbuildConfig => {
18
- const {styledJsxEnabled = true, modifyConfig} = params;
17
+ export const getBabelConfig = (params: GetBabelConfigParams = {}): RsbuildConfig => {
18
+ const { styledJsxEnabled = true, modifyConfig } = params;
19
19
 
20
20
  return {
21
21
  plugins: [
@@ -23,7 +23,7 @@ export const getBabelConfig = (params:GetBabelConfigParams = {}): RsbuildConfig
23
23
  pluginBabel({
24
24
  babelLoaderOptions: (config) => {
25
25
  // 添加styled-jsx的使用
26
- if(styledJsxEnabled) config.plugins?.push([
26
+ if (styledJsxEnabled) config.plugins?.push([
27
27
  "styled-jsx/babel",
28
28
  {
29
29
  "vendorPrefixes": true, // 为css自动添加前缀
@@ -34,7 +34,7 @@ export const getBabelConfig = (params:GetBabelConfigParams = {}): RsbuildConfig
34
34
  }
35
35
  ]);
36
36
 
37
- if(modifyConfig) modifyConfig(config)
37
+ if (modifyConfig) modifyConfig(config)
38
38
  },
39
39
  }),
40
40
  ]
@@ -44,9 +44,10 @@ export const getBabelConfig = (params:GetBabelConfigParams = {}): RsbuildConfig
44
44
  /**
45
45
  * 配置cesium engine
46
46
  */
47
- export const getCesiumEngineConfig = ({ srcDirPath, distDirPath }: {
47
+ export const getCesiumEngineConfig = ({ srcDirPath, distDirPath, modifyCodeEnable = true }: {
48
48
  srcDirPath: string, // cesium engine的基础目录路基
49
49
  distDirPath: string, // 目标路径
50
+ modifyCodeEnable?: boolean, // 是否允许修改源代码
50
51
  }): RsbuildConfig => {
51
52
  // const cesiumEngineBase = '../vendor/node_modules/@cesium/engine'; // cesium engine的源码目录
52
53
  // const distDir = "static"; // 目标目录
@@ -78,11 +79,11 @@ export const getCesiumEngineConfig = ({ srcDirPath, distDirPath }: {
78
79
  tools: {
79
80
  rspack: {
80
81
  // 注意: rsbuild编译代码时import.meta不支持,暂时将import.meta替换成'{}'空对象
81
- plugins: [
82
- new rspack.DefinePlugin({
83
- 'import.meta': '{}'
84
- })
85
- ],
82
+ // plugins: [
83
+ // new rspack.DefinePlugin({
84
+ // 'import.meta': '{}'
85
+ // })
86
+ // ],
86
87
  module: {
87
88
  rules: [
88
89
  // 添加.glsl文件转为字符串
@@ -96,6 +97,45 @@ export const getCesiumEngineConfig = ({ srcDirPath, distDirPath }: {
96
97
  },
97
98
  }
98
99
 
100
+
101
+ if (modifyCodeEnable) {
102
+ //***********************************修改源码start****************************************
103
+ /*
104
+ //d frontToBack添加try catch的原因, 调用Cesium.DrawCommand并传入Cesium.PASS.TRANSLUCENT(半透明物体)时,在监听点击或鼠标移动事件等时, 会报错: TypeError: Cannot read properties of undefined (reading 'distanceSquaredTo')
105
+ // 这样会影响程序的运行,所以暂时添加try catch来抑制异常的抛出
106
+ new Cesium.DrawCommand({
107
+ ...
108
+ ...
109
+ pass: Cesium.PASS.TRANSLUCENT,
110
+ });
111
+ */
112
+ const fs = require('fs');
113
+ const srcFilePath = `${srcDirPath}/Source/Scene/Scene.js`;
114
+ const data = fs.readFileSync(srcFilePath, 'utf-8');
115
+ const replaced = data.replace(`function frontToBack(a, b, position) {
116
+ // When distances are equal equal favor sorting b before a. This gives render priority to commands later in the list.
117
+ return (
118
+ a.boundingVolume.distanceSquaredTo(position) -
119
+ b.boundingVolume.distanceSquaredTo(position) +
120
+ CesiumMath.EPSILON12
121
+ );
122
+ }`, `function frontToBack(a, b, position) {
123
+ // When distances are equal equal favor sorting b before a. This gives render priority to commands later in the list.
124
+ try{
125
+ return (
126
+ a.boundingVolume.distanceSquaredTo(position) -
127
+ b.boundingVolume.distanceSquaredTo(position) +
128
+ CesiumMath.EPSILON12
129
+ );
130
+ }catch(e){
131
+
132
+ }
133
+ }`);
134
+
135
+ fs.writeFileSync(srcFilePath, replaced, 'utf-8')
136
+ }
137
+
138
+
99
139
  // TODO: 开发环境下copy Build/Workers正常,生成环境下打包copy Build/Workers会报如下错误:
100
140
  // × JavaScript parsing error: 'import', and 'export' cannot be used outside of module code
101
141
  // ╭─[24:1]
@@ -108,19 +148,18 @@ export const getCesiumEngineConfig = ({ srcDirPath, distDirPath }: {
108
148
  // ╰────
109
149
  // 所以在生成环境下打包不器用copy Build/Workers, 而是采用打包换成后再将Build/Workers放到指定目录中,
110
150
  // copy过程暂时发到package.json scripts build命令中了,请参照
111
-
151
+
112
152
  if (!isProd) {
113
153
  if (config.output?.copy) {
114
154
  (config.output?.copy as any[]).push({
115
155
  from: path.join(srcDirPath, 'Build/Workers'), to: distDirPath + '/Workers'
116
156
  })
117
157
  }
118
- }else{
158
+ } else {
119
159
  setTimeout(() => {
120
- // console.log("1111111111111111111111111111111111111111111111111111111");
121
- const dist = path.join(path.resolve('./'), "dist/"+distDirPath+"/Workers");
122
- if(!fs.existsSync(dist)) fs.mkdirSync(dist, {recursive: true});
123
- helper.copy(path.join(srcDirPath, 'Build/Workers'),dist)
160
+ const dist = path.join(path.resolve('./'), "dist/" + distDirPath + "/Workers");
161
+ if (!fs.existsSync(dist)) fs.mkdirSync(dist, { recursive: true });
162
+ helper.copy(path.join(srcDirPath, 'Build/Workers'), dist)
124
163
  }, 3000)
125
164
  }
126
165
 
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "rsbuild-pipe",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "author": "chencheng <daniel_txy@163.com>",
5
5
  "description": "rsbuild pipe",
6
6
  "main": "index",
7
7
  "dependencies": {
8
- "@rsbuild/core": "0.6.15",
9
- "@rsbuild/plugin-babel": "0.6.15",
10
- "@rsbuild/plugin-basic-ssl": "0.6.15",
11
- "@rsbuild/plugin-node-polyfill": "0.6.15",
12
- "@rsbuild/plugin-react": "0.6.15",
13
- "@rsbuild/plugin-svgr": "0.6.15",
14
- "@rsbuild/plugin-type-check": "0.6.15",
15
- "@types/node": "20.12.12",
8
+ "@rsbuild/core": "0.7.1",
9
+ "@rsbuild/plugin-babel": "0.7.1",
10
+ "@rsbuild/plugin-basic-ssl": "0.7.1",
11
+ "@rsbuild/plugin-less": "0.7.1",
12
+ "@rsbuild/plugin-node-polyfill": "0.7.1",
13
+ "@rsbuild/plugin-react": "0.7.1",
14
+ "@rsbuild/plugin-sass": "0.7.1",
15
+ "@rsbuild/plugin-svgr": "0.7.1",
16
+ "@rsbuild/plugin-type-check": "0.7.1",
17
+ "@types/node": "20.12.13",
16
18
  "deepmerge": "4.3.1"
17
19
  },
18
20
  "repository": {