rsbuild-pipe 1.0.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 ADDED
@@ -0,0 +1,9 @@
1
+ # rsbuild-pipe
2
+
3
+ rsbuild开发和打包管道
4
+
5
+ ## Change Log
6
+ v1.0.0
7
+ ```
8
+
9
+ ```
package/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./lib/rsbuild.base.config";
2
+ export * as extendConfig from "./lib/rsbuild.extend.config";
package/lib/helper.ts ADDED
@@ -0,0 +1,23 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+
4
+
5
+ export const copy = (sd, td) => {
6
+ // 读取目录下的文件,返回文件名及文件类型{name: 'xxx.txt, [Symbol(type)]: 1 }
7
+ const sourceFile = fs.readdirSync(sd, { withFileTypes: true })
8
+ for (const file of sourceFile) {
9
+ // 源文件 地址+文件名
10
+ const srcFile = path.resolve(sd, file.name)
11
+ // 目标文件
12
+ const tagFile = path.resolve(td, file.name)
13
+ // 文件是目录且未创建
14
+ if (file.isDirectory() && !fs.existsSync(tagFile)) {
15
+ fs.mkdirSync(tagFile, err => console.log(err))
16
+ copy(srcFile, tagFile)
17
+ } else if (file.isDirectory() && fs.existsSync(tagFile)) {
18
+ // 文件时目录且已存在
19
+ copy(srcFile, tagFile)
20
+ }
21
+ !file.isDirectory() && fs.copyFileSync(srcFile, tagFile, fs.constants.COPYFILE_FICLONE)
22
+ }
23
+ }
@@ -0,0 +1,98 @@
1
+ import { mergeRsbuildConfig, type RsbuildConfig } from '@rsbuild/core';
2
+ import { pluginReact, type PluginReactOptions } from '@rsbuild/plugin-react';
3
+ import { pluginSvgr, PluginSvgrOptions } from "@rsbuild/plugin-svgr";
4
+ import { pluginTypeCheck, PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check';
5
+ import { pluginBasicSsl } from '@rsbuild/plugin-basic-ssl';
6
+
7
+ export * as helper from "./helper";
8
+ export * from "@rsbuild/core";
9
+ export * from '@rsbuild/plugin-react';
10
+ export * from "@rsbuild/plugin-svgr";
11
+ export * from '@rsbuild/plugin-type-check';
12
+ export * from '@rsbuild/plugin-basic-ssl';
13
+ const deepmerge = require("deepmerge");
14
+
15
+ export { deepmerge };
16
+ export const isProd = process.env.NODE_ENV === 'production'; // 是否为生成环境打包
17
+
18
+ interface GetBaseConfigParams {
19
+ rsbuildConfig?: RsbuildConfig,
20
+ pluginBasicSslEnable?: boolean, // 是否使用插件: @rsbuild/plugin-basic-ssl
21
+ pluginReactEnable?: boolean, // 是否使用插件: @rsbuild/plugin-react
22
+ pluginReactOptions?: PluginReactOptions,
23
+ pluginSvgrEnable?: boolean, // 是否使用插件: @rsbuild/plugin-svgr
24
+ pluginSvgrOptions?: PluginSvgrOptions,
25
+ pluginTypeCheckEnable?: boolean, // 是否使用插件: @rsbuild/plugin-type-check
26
+ pluginTypeCheckerOptions?: PluginTypeCheckerOptions,
27
+ };
28
+
29
+ export const getBaseConfig = (params: GetBaseConfigParams = {}):RsbuildConfig => {
30
+ const {
31
+ rsbuildConfig = {},
32
+ pluginBasicSslEnable = false,
33
+ pluginReactEnable = true,
34
+ pluginReactOptions = {},
35
+ pluginSvgrEnable = true,
36
+ pluginSvgrOptions = {},
37
+ pluginTypeCheckEnable = true,
38
+ pluginTypeCheckerOptions = {},
39
+ } = params;
40
+
41
+ return mergeRsbuildConfig({
42
+ html: {
43
+ template: "./public/index.html"
44
+ },
45
+ // 1. 入口配置
46
+ source: {
47
+ entry: {
48
+ index: './src',
49
+ },
50
+ alias: {
51
+ '@/': './src/',
52
+ 'vendor/': '../vendor/',
53
+ },
54
+ },
55
+ // 开发服务器配置
56
+ server: {
57
+ publicDir: {
58
+ name: "./public", // 作为静态资源服务的文件夹
59
+ copyOnBuild: false,
60
+ },
61
+ htmlFallback: false,
62
+ historyApiFallback: {
63
+ index: '/index.html',
64
+ },
65
+ },
66
+ output: {
67
+ overrideBrowserslist: [
68
+ // 'chrome >= 87', 'edge >= 88', 'firefox >= 78', 'safari >= 14',
69
+ 'chrome >= 100'
70
+ ]
71
+ },
72
+ // 插件配置
73
+ plugins: [
74
+ // react插件true
75
+ pluginReactEnable ? pluginReact(pluginReactOptions) : null,
76
+
77
+ // typescript 语法检查,注意语法错误只能在命令行中输出,不能再页面中输出
78
+ pluginTypeCheckEnable ? pluginTypeCheck(deepmerge({
79
+ forkTsCheckerOptions: {
80
+ async: true,
81
+ devServer: true, // 输出到webpack-dev-server服务中
82
+ typescript: {
83
+ memoryLimit: 2048
84
+ }
85
+ }
86
+ }, pluginTypeCheckerOptions)): null,
87
+
88
+ // svg转为react组件
89
+ pluginSvgrEnable ? pluginSvgr(deepmerge({
90
+ mixedImport: true,
91
+ }, pluginSvgrOptions)) : null,
92
+
93
+ // 是否使用自签名的https证书
94
+ pluginBasicSslEnable ? pluginBasicSsl() : null,
95
+ ],
96
+ }, rsbuildConfig);
97
+ }
98
+
@@ -0,0 +1,128 @@
1
+ import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
2
+ import { pluginBabel, PluginBabelOptions } from '@rsbuild/plugin-babel';
3
+
4
+ import { isProd, rspack, helper, type RsbuildConfig } from './rsbuild.base.config';
5
+ const path = require("path");
6
+ const fs = require("fs");
7
+
8
+ interface GetBabelConfigParams{
9
+ styledJsxEnabled?: boolean,
10
+ modifyConfig?:(config:PluginBabelOptions["babelLoaderOptions"]) => PluginBabelOptions["babelLoaderOptions"],
11
+ }
12
+
13
+ /**
14
+ * 参数文档配置: https://rsbuild.dev/zh/plugins/list/plugin-babel
15
+ * 获取babel配置
16
+ */
17
+ export const getBabelConfig = (params:GetBabelConfigParams = {}): RsbuildConfig => {
18
+ const {styledJsxEnabled = true, modifyConfig} = params;
19
+
20
+ return {
21
+ plugins: [
22
+ // babel插件
23
+ pluginBabel({
24
+ babelLoaderOptions: (config) => {
25
+ // 添加styled-jsx的使用
26
+ if(styledJsxEnabled) config.plugins?.push([
27
+ "styled-jsx/babel",
28
+ {
29
+ "vendorPrefixes": true, // 为css自动添加前缀
30
+ "optimizeForSpeed": isProd, // 是否优化
31
+ "plugins": [
32
+ ["styled-jsx-plugin-sass", { sassOptions: {} }]
33
+ ]
34
+ }
35
+ ]);
36
+
37
+ if(modifyConfig) modifyConfig(config)
38
+ },
39
+ }),
40
+ ]
41
+ }
42
+ }
43
+
44
+ /**
45
+ * 配置cesium engine
46
+ */
47
+ export const getCesiumEngineConfig = ({ srcDirPath, distDirPath }: {
48
+ srcDirPath: string, // cesium engine的基础目录路基
49
+ distDirPath: string, // 目标路径
50
+ }): RsbuildConfig => {
51
+ // const cesiumEngineBase = '../vendor/node_modules/@cesium/engine'; // cesium engine的源码目录
52
+ // const distDir = "static"; // 目标目录
53
+
54
+ const config: RsbuildConfig = {
55
+ output: {
56
+ copy: [
57
+ // { from: path.join(srcDirPath, 'Build/Workers'), to: distDirPath+'/Workers' },
58
+ { from: path.join(srcDirPath, 'Source/Assets'), to: distDirPath + '/Assets' },
59
+ { from: path.join(srcDirPath, 'Build/ThirdParty'), to: distDirPath + '/ThirdParty' },
60
+ ],
61
+ },
62
+ plugins: [
63
+ pluginNodePolyfill({
64
+ globals: {
65
+ // @ts-ignore
66
+ https: false,
67
+ http: false,
68
+ zlib: false,
69
+ url: false,
70
+ buffer: false,
71
+ assert: false,
72
+ util: false,
73
+ stream: false,
74
+ }
75
+ })
76
+ ],
77
+
78
+ 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
+
99
+ // TODO: 开发环境下copy Build/Workers正常,生成环境下打包copy Build/Workers会报如下错误:
100
+ // × JavaScript parsing error: 'import', and 'export' cannot be used outside of module code
101
+ // ╭─[24:1]
102
+ // 24 │ */
103
+ // 25 │
104
+ // 26 │ import {
105
+ // · ──────
106
+ // 27 │ defined_default
107
+ // 28 │ } from "./chunk-YBKFS53K.js";
108
+ // ╰────
109
+ // 所以在生成环境下打包不器用copy Build/Workers, 而是采用打包换成后再将Build/Workers放到指定目录中,
110
+ // copy过程暂时发到package.json scripts build命令中了,请参照
111
+
112
+ if (!isProd) {
113
+ if (config.output?.copy) {
114
+ (config.output?.copy as any[]).push({
115
+ from: path.join(srcDirPath, 'Build/Workers'), to: distDirPath + '/Workers'
116
+ })
117
+ }
118
+ }else{
119
+ 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)
124
+ }, 3000)
125
+ }
126
+
127
+ return config;
128
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "rsbuild-pipe",
3
+ "version": "1.0.0",
4
+ "author": "chencheng <daniel_txy@163.com>",
5
+ "description": "rsbuild pipe",
6
+ "main": "index",
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",
16
+ "deepmerge": "4.3.1"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://gitee.com/cloud_soldier/rsbuild-pipe.git"
21
+ },
22
+ "license": "ISC",
23
+ "bugs": {
24
+ "url": "https://gitee.com/cloud_soldier/rsbuild-pipe/ssues"
25
+ },
26
+ "homepage": "https://gitee.com/cloud_soldier/rsbuild-pipe#readme",
27
+ "devDependencies": {
28
+ "typescript": "5.4.5"
29
+ }
30
+ }