FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gpu.js/scripts/build.js at develop · gpujs/gpu.js · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
gpujs
/
gpu.js
Public
Notifications
You must be signed in to change notification settings
Fork
663
Star
15.4k
Code
Issues
64
Pull requests
2
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
gpu.js
/
scripts
/
build.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
81 lines (74 loc) · 2.94 KB
Breadcrumbs
gpu.js
/
scripts
/
build.js
Copy path
File metadata and controls
81 lines (74 loc) · 2.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Bundles src/browser.js into the two browser builds. Replaces gulp's `build`.
const
path
=
require
(
'path'
)
;
const
{
rolldown
}
=
require
(
'rolldown'
)
;
const
decomment
=
require
(
'decomment'
)
;
const
{
minify
}
=
require
(
'terser'
)
;
const
{
ROOT
,
withBanner
,
write
}
=
require
(
'./lib'
)
;
const
EMPTY_MODULE
=
path
.
join
(
__dirname
,
'empty-module.js'
)
;
/**
* `format: 'umd'` + `name` is what browserify's `standalone` produced: the UMD
* wrapper and the GPU global that src/browser.js then binds over.
*
* Aliasing to an empty module is browserify's `.ignore()`, and it has to be an
* alias rather than `external`: external would leave a live require() in the
* bundle, which throws in a browser. `gl` is a native node addon that cannot
* exist there, and the core build additionally drops acorn.
*
* mainFields pins resolution to the CommonJS entry of each dependency, which is
* what browserify used. Left alone rolldown prefers the ESM entry, and gl's
* package.json also carries a browser field that browserField:false told
* browserify to ignore.
*/
async
function
bundle
(
ignore
)
{
const
build
=
await
rolldown
(
{
input
:
path
.
join
(
ROOT
,
'src'
,
'browser.js'
)
,
platform
:
'browser'
,
resolve
:
{
alias
:
Object
.
fromEntries
(
ignore
.
map
(
name
=>
[
name
,
EMPTY_MODULE
]
)
)
,
mainFields
:
[
'main'
]
,
}
,
}
)
;
const
{
output
}
=
await
build
.
generate
(
{
format
:
'umd'
,
name
:
'GPU'
,
}
)
;
await
build
.
close
(
)
;
return
output
[
0
]
.
code
;
}
/**
* Re-emits the bundle with every non-ASCII character escaped, leaving it
* otherwise intact — no compression, no mangling.
*
* acorn ships its unicode identifier tables already escaped (\xb7…)
* and browserify passed those through verbatim, but rolldown decodes string
* literals and prints the characters, putting ~68k raw UTF-8 bytes in the
* bundle. Anything serving dist/ without a matching charset then corrupts them,
* which is #743 and #744 all over again.
*
* terser is used rather than a regex sweep because it parses the code and so
* only escapes where an escape is actually equivalent.
*/
async
function
toAscii
(
code
,
name
)
{
const
result
=
await
minify
(
{
[
name
]
:
code
}
,
{
compress
:
false
,
mangle
:
false
,
format
:
{
ascii_only
:
true
,
beautify
:
true
,
comments
:
false
,
indent_level
:
2
}
,
}
)
;
if
(
result
.
error
)
throw
result
.
error
;
return
result
.
code
;
}
async
function
build
(
)
{
// worker_threads and os are the wasm worker pool's Node half; in the
// browser it detects `Worker` first and never touches them
const
full
=
await
bundle
(
[
'gl'
,
'worker_threads'
,
'os'
]
)
;
write
(
'dist/gpu-browser.js'
,
withBanner
(
await
toAscii
(
decomment
(
full
)
,
'gpu-browser.js'
)
)
)
;
const
core
=
await
bundle
(
[
'gl'
,
'acorn'
,
'worker_threads'
,
'os'
]
)
;
write
(
'dist/gpu-browser-core.js'
,
withBanner
(
await
toAscii
(
decomment
(
core
)
,
'gpu-browser-core.js'
)
)
)
;
}
if
(
require
.
main
===
module
)
{
build
(
)
.
catch
(
error
=>
{
console
.
error
(
error
)
;
process
.
exit
(
1
)
;
}
)
;
}
module
.
exports
=
{
build
}
;
Back
|
FazBrowse Home
|
New Git URL