mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
[bun.js] Improve support for bundling for node.js
This commit is contained in:
2
Makefile
2
Makefile
@@ -474,6 +474,8 @@ fallback_decoder:
|
||||
runtime_js:
|
||||
@NODE_ENV=production esbuild --define:process.env.NODE_ENV="production" --target=esnext --bundle src/runtime/index.ts --format=iife --platform=browser --global-name=BUN_RUNTIME --minify --external:/bun:* > src/runtime.out.js; cat src/runtime.footer.js >> src/runtime.out.js
|
||||
@NODE_ENV=production esbuild --define:process.env.NODE_ENV="production" --target=esnext --bundle src/runtime/index-with-refresh.ts --format=iife --platform=browser --global-name=BUN_RUNTIME --minify --external:/bun:* > src/runtime.out.refresh.js; cat src/runtime.footer.with-refresh.js >> src/runtime.out.refresh.js
|
||||
@NODE_ENV=production esbuild --define:process.env.NODE_ENV="production" --target=esnext --bundle src/runtime/index-without-hmr.ts --format=iife --platform=node --global-name=BUN_RUNTIME --minify --external:/bun:* > src/runtime.node.pre.out.js; cat src/runtime.node.pre.out.js src/runtime.footer.node.js > src/runtime.node.out.js
|
||||
@NODE_ENV=production esbuild --define:process.env.NODE_ENV="production" --target=esnext --bundle src/runtime/index-without-hmr.ts --format=iife --platform=node --global-name=BUN_RUNTIME --minify --external:/bun:* > src/runtime.bun.pre.out.js; cat src/runtime.bun.pre.out.js src/runtime.footer.bun.js > src/runtime.bun.out.js
|
||||
|
||||
runtime_js_dev:
|
||||
@NODE_ENV=development esbuild --define:process.env.NODE_ENV="development" --target=esnext --bundle src/runtime/index.ts --format=iife --platform=browser --global-name=BUN_RUNTIME --external:/bun:* > src/runtime.out.js; cat src/runtime.footer.js >> src/runtime.out.js
|
||||
|
||||
83
src/runtime.footer.node.js
Normal file
83
src/runtime.footer.node.js
Normal file
@@ -0,0 +1,83 @@
|
||||
import * as __$module from "node:module";
|
||||
export var $$m = BUN_RUNTIME.$$m;
|
||||
export var __markAsModule = BUN_RUNTIME.__markAsModule;
|
||||
export var $$lzy = BUN_RUNTIME.$$lzy;
|
||||
export var __toModule = BUN_RUNTIME.__toModule;
|
||||
export var __commonJS = BUN_RUNTIME.__commonJS;
|
||||
export var __require = BUN_RUNTIME.__require;
|
||||
export var __name = BUN_RUNTIME.__name;
|
||||
export var __export = BUN_RUNTIME.__export;
|
||||
export var __reExport = BUN_RUNTIME.__reExport;
|
||||
export var __cJS2eSM = BUN_RUNTIME.__cJS2eSM;
|
||||
export var regeneratorRuntime = BUN_RUNTIME.regeneratorRuntime;
|
||||
export var __exportValue = BUN_RUNTIME.__exportValue;
|
||||
export var __exportDefault = BUN_RUNTIME.__exportDefault;
|
||||
export var $$bun_runtime_json_parse = JSON.parse;
|
||||
export var __internalIsCommonJSNamespace =
|
||||
BUN_RUNTIME.__internalIsCommonJSNamespace;
|
||||
var require = __$module.createRequire(import.meta.url);
|
||||
var process =
|
||||
globalThis.process ||
|
||||
new Proxy(
|
||||
{},
|
||||
{
|
||||
get: function (target, prop, receiver) {
|
||||
var _process = require("process");
|
||||
target = process = _process;
|
||||
return Reflect.get(_process, prop, receiver);
|
||||
},
|
||||
apply: function (target, thisArg, argumentsList) {
|
||||
var _process = require("process");
|
||||
target = process = _process;
|
||||
return Reflect.apply(target, thisArg, argumentsList);
|
||||
},
|
||||
defineProperty(target, key, descriptor) {
|
||||
var _process = require("process");
|
||||
target = process = _process;
|
||||
return Reflect.defineProperty(_process, key, descriptor);
|
||||
},
|
||||
construct: function (target, args) {
|
||||
var _process = require("process");
|
||||
target = process = _process;
|
||||
return Reflect.construct(_process, args);
|
||||
},
|
||||
has: function (target, prop, receiver) {
|
||||
var _process = require("process");
|
||||
target = process = _process;
|
||||
return Reflect.has(_process, prop, receiver);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
var Buffer =
|
||||
globalThis.Buffer ||
|
||||
new Proxy(
|
||||
{},
|
||||
{
|
||||
get: function (target, prop, receiver) {
|
||||
var NewBuffer = require("buffer").Buffer;
|
||||
target = Buffer = NewBuffer;
|
||||
return Reflect.get(NewBuffer, prop, receiver);
|
||||
},
|
||||
apply: function (target, thisArg, argumentsList) {
|
||||
var NewBuffer = require("buffer").Buffer;
|
||||
target = Buffer = NewBuffer;
|
||||
return Reflect.apply(target, thisArg, argumentsList);
|
||||
},
|
||||
defineProperty(target, key, descriptor) {
|
||||
var NewBuffer = require("buffer").Buffer;
|
||||
target = Buffer = NewBuffer;
|
||||
return Reflect.defineProperty(NewBuffer, key, descriptor);
|
||||
},
|
||||
construct: function (target, args) {
|
||||
var NewBuffer = require("buffer").Buffer;
|
||||
target = Buffer = NewBuffer;
|
||||
return Reflect.construct(NewBuffer, args);
|
||||
},
|
||||
has: function (target, prop, receiver) {
|
||||
var NewBuffer = require("buffer").Buffer;
|
||||
target = Buffer = NewBuffer;
|
||||
return Reflect.has(NewBuffer, prop, receiver);
|
||||
},
|
||||
}
|
||||
);
|
||||
@@ -164,6 +164,7 @@ pub const Fallback = struct {
|
||||
|
||||
pub const Runtime = struct {
|
||||
pub const ProdSourceContent = @embedFile("./runtime.out.js");
|
||||
pub const ProdSourceContentNode = @embedFile("./runtime.node.out.js");
|
||||
pub const ProdSourceContentBun = @embedFile("./runtime.bun.out.js");
|
||||
pub const ProdSourceContentWithRefresh = @embedFile("./runtime.out.refresh.js");
|
||||
|
||||
@@ -193,6 +194,10 @@ pub const Runtime = struct {
|
||||
return sourceContentWithoutRefresh();
|
||||
}
|
||||
|
||||
pub inline fn sourceContentNode() string {
|
||||
return ProdSourceContentNode;
|
||||
}
|
||||
|
||||
pub inline fn sourceContentBun() string {
|
||||
return ProdSourceContentBun;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user