Skip to content

Commit 6c649d9

Browse files
author
Taois
committed
init: 提交了drpy打包项目
1 parent 0b3b017 commit 6c649d9

35 files changed

+47503
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ out
8080

8181
# Nuxt.js build / generate output
8282
.nuxt
83-
dist
8483

8584
# Gatsby files
8685
.cache/
@@ -137,3 +136,5 @@ dist
137136
# Vite logs files
138137
vite.config.js.timestamp-*
139138
vite.config.ts.timestamp-*
139+
/.idea/
140+
/true/

dist/drpy-core.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "drpy-webpack",
3+
"version": "1.0.1",
4+
"main": "webpack.config.js",
5+
"type": "module",
6+
"scripts": {
7+
"build": "webpack --config webpack.config.js"
8+
},
9+
"engines": {
10+
"node": ">21 <23"
11+
},
12+
"repository": "https://github.com/hjdhnx/drpy-webpack.git",
13+
"author": "晚风拂柳颜 <434857005@qq.com>",
14+
"description": "道长修仙,法力无边。一统江湖,只需半年。\n君子袒蛋蛋,小人藏鸡鸡。",
15+
"license": "MIT",
16+
"devDependencies": {
17+
"@babel/core": "^7.28.0",
18+
"@babel/plugin-proposal-class-properties": "^7.18.6",
19+
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
20+
"@babel/preset-env": "^7.28.0",
21+
"babel-loader": "^10.0.0",
22+
"script-loader": "^0.7.2",
23+
"terser-webpack-plugin": "^5.3.14",
24+
"webpack": "^5.100.2",
25+
"webpack-cli": "^6.0.1"
26+
}
27+
}

readme.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## drpy_webpack
2+
3+
drpy2框架的打包项目。所有依赖打包成一个drpy-core.min.js
4+
5+
当前版本号: `3.9.52beta2 20250729`
6+
7+
注意复制到drpyS项目 `public/drpy` 目录前需要把 init_test里的一些调试日志注释掉
8+
9+
### 构建过程参考命令
10+
11+
```bash
12+
# 创建项目目录并进入
13+
#mkdir webpack-project && cd webpack-project
14+
15+
# 初始化 package.json (一路回车或按需填写)
16+
yarn init -y
17+
18+
# 安装核心依赖
19+
yarn add webpack webpack-cli --dev
20+
yarn add terser-webpack-plugin --dev # 压缩插件
21+
22+
yarn add webpack webpack-cli babel-loader @babel/core @babel/preset-env --dev
23+
yarn add @babel/plugin-proposal-class-properties @babel/plugin-proposal-optional-chaining --dev
24+
yarn add script-loader --dev
25+
26+
```
27+
28+
执行编译的时候需要去掉package.json里的 `"type": "module",`,执行drpy-test.js测试的时候需要加回去

src/drpy-core.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// drpy-core.js
2+
import cheerio from './libs/cheerio.min.js';
3+
import template from './libs/模板.js'; // 使用英文名导入
4+
5+
// 导入所有依赖库
6+
import './libs/gb18030.min.js';
7+
import './libs/crypto-js.min.js';
8+
import './libs/jsencrypt.min.js';
9+
import './libs/node-rsa.min.js';
10+
import './libs/pako.min.js';
11+
import './libs/json5.min.js';
12+
import './libs/jsonpathplus.min.js';
13+
import './libs/jinja.min.js';
14+
import './libs/polywasm.min.js';
15+
import './libs/encoding.min.js'
16+
import './libs/xxhash-wasm.min.js';
17+
18+
// 确保全局依赖可用
19+
20+
const gbkTool = globalThis.gbkTool;
21+
const CryptoJS = globalThis.CryptoJS;
22+
const JSEncrypt = globalThis.JSEncrypt;
23+
const NODERSA = globalThis.NODERSA;
24+
const pako = globalThis.pako;
25+
const JSON5 = globalThis.JSON5;
26+
const JSONPath = globalThis.JSONPath;
27+
const jinja = globalThis.jinja;
28+
const WebAssembly = globalThis.WebAssembly;
29+
const TextEncoder = globalThis.TextEncoder;
30+
const TextDecoder = globalThis.TextDecoder;
31+
32+
33+
// const cheerio = {
34+
// jinja2(template, obj) {
35+
// return jinja.render(template, obj);
36+
// },
37+
// jp(path, json) {
38+
// return JSONPath.JSONPath({
39+
// path,
40+
// json
41+
// })[0];
42+
// }
43+
// }
44+
45+
const _jinja2 = cheerio.jinja2;
46+
cheerio.jinja2 = function (template, obj) {
47+
try {
48+
return jinja.render(template, obj);
49+
} catch (e) {
50+
console.log('新的jinja2库渲染失败,换回原始cheerio:' + e.message);
51+
return _jinja2(template, obj)
52+
}
53+
};
54+
cheerio.jp = function (path, json) {
55+
return JSONPath.JSONPath({
56+
path,
57+
json
58+
})[0];
59+
};
60+
61+
62+
// 导出所有需要暴露的内容
63+
export {
64+
cheerio,
65+
template as 模板, // 使用别名导出中文标识符
66+
gbkTool,
67+
CryptoJS,
68+
JSEncrypt,
69+
NODERSA,
70+
pako,
71+
JSON5,
72+
JSONPath,
73+
jinja,
74+
WebAssembly,
75+
TextEncoder,
76+
TextDecoder,
77+
};

src/drpy-test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {cheerio, 模板} from '../dist/drpy-core.min.js';
2+
// import {cheerio, JSONPath, TextDecoder, TextEncoder, 模板} from './drpy-core.js';
3+
4+
console.log('typeof 模板:', typeof (模板))
5+
console.log('typeof cheerio:', typeof (cheerio))
6+
// console.log(模板)
7+
console.log('typeof gbkTool:', typeof gbkTool);
8+
console.log('typeof CryptoJS:', typeof CryptoJS);
9+
console.log('typeof JSEncrypt:', typeof JSEncrypt);
10+
console.log('typeof NODERSA:', typeof NODERSA);
11+
console.log('typeof pako:', typeof pako);
12+
console.log('typeof JSON5:', typeof JSON5);
13+
console.log('typeof JSONPath:', typeof JSONPath);
14+
console.log('typeof jinja:', typeof jinja);
15+
console.log('typeof WebAssembly:', typeof WebAssembly);
16+
console.log('typeof TextEncoder:', typeof TextEncoder);
17+
console.log('typeof TextDecoder:', typeof TextDecoder);
18+
console.log('typeof WXXH:', typeof WXXH);
19+
20+
console.log(gbkTool.encode('你好'));
21+
console.log(gbkTool.decode('%C4%E3%BA%C3'));
22+
23+
const s = '{"method":"GET","timestamp":1745206708456,"path":"/index/fuck","parameters":{"timestamp":["1745206708456"]},"body":""}';
24+
const seed = 1745206708;
25+
const hash = WXXH.h64(s, seed).toString(16);
26+
console.log(`WASM:${hash}`);
27+
28+
console.log(cheerio.jinja2('渲染一个变量{{hash}}', {hash}));
29+
console.log('jsonpath取值测试:', cheerio.jp('$.name', {name: '道长', project: 'drpys'}));

0 commit comments

Comments
 (0)