File tree Expand file tree Collapse file tree 7 files changed +97
-29
lines changed
Expand file tree Collapse file tree 7 files changed +97
-29
lines changed Original file line number Diff line number Diff line change 1+ const esbuild = require ( 'esbuild' )
2+ const { NodeModulesPolyfillPlugin} = require ( '@esbuild-plugins/node-modules-polyfill' )
3+ const path = require ( 'path' )
4+
5+ // 多入口配置
6+ const entryPoints = {
7+ 'drpy-core' : './src/drpy-core.js' ,
8+ 'drpy-core-lite' : './src/drpy-core-lite.js'
9+ }
10+
11+ // 共享配置
12+ const sharedConfig = {
13+ entryPoints,
14+ bundle : true ,
15+ minify : true ,
16+ sourcemap : false ,
17+ target : [ 'es2020' ] ,
18+ legalComments : 'none' ,
19+ charset : 'utf8' ,
20+ platform : 'browser' ,
21+ format : 'esm' ,
22+ // format: 'iife', // 使用立即执行函数
23+ // globalName: 'globalThis', // 设置全局命名空间
24+ outdir : 'dist' ,
25+ outExtension : { '.js' : '.min.js' } ,
26+ keepNames : true , // 保留函数/类名
27+ alias : {
28+ '模板' : path . resolve ( __dirname , 'src/模板.js' )
29+ } ,
30+ plugins : [
31+ // 处理 Node.js 模块 polyfill
32+ NodeModulesPolyfillPlugin ( )
33+ ] ,
34+ loader : {
35+ '.js' : 'js'
36+ } ,
37+ define : {
38+ 'process.env.NODE_ENV' : '"production"' ,
39+ 'globalThis' : 'globalThis' ,
40+ 'window.globalThis' : 'globalThis'
41+ } ,
42+ logOverride : {
43+ // 忽略这个特定警告
44+ 'suspicious-boolean-not' : 'silent'
45+ } ,
46+ // 关键修复:确保全局导出可用
47+ banner : {
48+ js : `const g = typeof window !== 'undefined' ? window :
49+ typeof global !== 'undefined' ? global : globalThis;`
50+ }
51+ }
52+
53+ // 执行构建
54+ esbuild . build ( sharedConfig )
55+ . then ( ( ) => console . log ( '构建完成!' ) )
56+ . catch ( ( ) => process . exit ( 1 ) )
Original file line number Diff line number Diff line change 22 "name" : " drpy-webpack" ,
33 "version" : " 1.0.2" ,
44 "main" : " webpack.config.js" ,
5-
65 "scripts" : {
7- "build" : " webpack --config webpack.config.js"
6+ "build" : " webpack --config webpack.config.js" ,
7+ "esbuild" : " node esbuild.config.js"
88 },
9+ "type" : " module" ,
910 "engines" : {
1011 "node" : " >21 <23"
1112 },
1819 "@babel/plugin-proposal-class-properties" : " ^7.18.6" ,
1920 "@babel/plugin-proposal-optional-chaining" : " ^7.21.0" ,
2021 "@babel/preset-env" : " ^7.28.0" ,
22+ "@esbuild-plugins/node-modules-polyfill" : " ^0.2.2" ,
2123 "babel-loader" : " ^10.0.0" ,
24+ "esbuild" : " ^0.25.8" ,
2225 "script-loader" : " ^0.7.2" ,
2326 "terser-webpack-plugin" : " ^5.3.14" ,
2427 "webpack" : " ^5.100.2" ,
Original file line number Diff line number Diff line change @@ -27,4 +27,13 @@ yarn add script-loader --dev
2727
2828```
2929
30- 执行编译的时候需要去掉package.json里的 ` "type": "module", ` ,执行drpy-test.js测试的时候需要加回去
30+ 执行编译的时候需要去掉package.json里的 ` "type": "module", ` ,执行drpy-test.js测试的时候需要加回去
31+
32+ ### 新增esbuild打包
33+
34+ 已知问题。打包后的东西全局变量不正常,没法用,先研究到这儿,后面有时间再说。
35+ 唯一看中的优势就是这个打包工具比webpack来说速度贼快,速度超越 ` vite ` ` rollup ` 直逼 ` rolldown ` !
36+
37+ ``` shell
38+ yarn add esbuild @esbuild-plugins/node-modules-polyfill --dev
39+ ```
Original file line number Diff line number Diff line change @@ -18,18 +18,18 @@ import './libs/xxhash-wasm.min.js';
1818
1919
2020// 确保全局依赖可用
21-
22- const gbkTool = globalThis . gbkTool ;
23- const CryptoJS = globalThis . CryptoJS ;
24- const JSEncrypt = globalThis . JSEncrypt ;
25- const NODERSA = globalThis . NODERSA ; // lite版弃用
26- const pako = globalThis . pako ;
27- const JSON5 = globalThis . JSON5 ;
28- const JSONPath = globalThis . JSONPath ;
29- const jinja = globalThis . jinja ;
30- const WebAssembly = globalThis . WebAssembly ;
31- const TextEncoder = globalThis . TextEncoder ;
32- const TextDecoder = globalThis . TextDecoder ;
21+ const g = globalThis ;
22+ const gbkTool = g . gbkTool ;
23+ const CryptoJS = g . CryptoJS ;
24+ const JSEncrypt = g . JSEncrypt ;
25+ const NODERSA = g . NODERSA ; // lite版弃用
26+ const pako = g . pako ;
27+ const JSON5 = g . JSON5 ;
28+ const JSONPath = g . JSONPath ;
29+ const jinja = g . jinja ;
30+ const WebAssembly = g . WebAssembly ;
31+ const TextEncoder = g . TextEncoder ;
32+ const TextDecoder = g . TextDecoder ;
3333
3434/*
3535patch打补丁开始
Original file line number Diff line number Diff line change @@ -16,18 +16,18 @@ import './libs/encoding.min.js'
1616import './libs/xxhash-wasm.min.js' ;
1717
1818// 确保全局依赖可用
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 ;
19+ const g = globalThis ;
20+ const gbkTool = g . gbkTool ;
21+ const CryptoJS = g . CryptoJS ;
22+ const JSEncrypt = g . JSEncrypt ;
23+ const NODERSA = g . NODERSA ;
24+ const pako = g . pako ;
25+ const JSON5 = g . JSON5 ;
26+ const JSONPath = g . JSONPath ;
27+ const jinja = g . jinja ;
28+ const WebAssembly = g . WebAssembly ;
29+ const TextEncoder = g . TextEncoder ;
30+ const TextDecoder = g . TextDecoder ;
3131
3232
3333// const cheerio = {
You can’t perform that action at this time.
0 commit comments