Skip to content

Commit

Permalink
unflag experimental css and html (#16561)
Browse files Browse the repository at this point in the history
Co-authored-by: nektro <[email protected]>
Co-authored-by: Zack Radisic <[email protected]>
  • Loading branch information
3 people authored Jan 21, 2025
1 parent 4645eb8 commit af79ceb
Show file tree
Hide file tree
Showing 49 changed files with 431 additions and 896 deletions.
4 changes: 1 addition & 3 deletions docs/bundler/fullstack.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ Bun.serve({
});
```

You'll need to run your app with `bun --experimental-html` to enable this feature:

```bash
$ bun --experimental-html run app.ts
$ bun run app.ts
```

## HTML imports are routes
Expand Down
8 changes: 1 addition & 7 deletions docs/bundler/html.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ One command is all you need (won't be experimental after Bun v1.2):
{% codetabs %}

```bash#CLI
$ bun build --experimental-html --experimental-css ./index.html --outdir=dist
$ bun build ./index.html --outdir=dist
```

```ts#API
Bun.build({
entrypoints: ["./index.html"],
outdir: "./dist",
// On by default in Bun v1.2+
html: true,
experimentalCss: true,
});
```

Expand Down Expand Up @@ -63,8 +59,6 @@ Need more control? Configure the bundler through the JavaScript API and use Bun'
await Bun.build({
entrypoints: ["./index.html"],
outdir: "./dist",
html: true,
experimentalCss: true,
minify: true,

plugins: [
Expand Down
31 changes: 0 additions & 31 deletions docs/bundler/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1258,30 +1258,6 @@ $ bun build ./index.tsx --outdir ./out --drop=console --drop=debugger --drop=any

{% /codetabs %}

### `experimentalCss`

Whether to enable _experimental_ support for bundling CSS files. Defaults to `false`. In 1.2, this property will be deleted, and CSS bundling will always be enabled.

This supports bundling CSS files imported from JS, as well as CSS entrypoints.

{% codetabs group="a" %}

```ts#JavaScript
const result = await Bun.build({
entrypoints: ["./index.ts"],
experimentalCss: true,
});
// => { success: boolean, outputs: BuildArtifact[], logs: BuildMessage[] }
```

{% /codetabs %}

### `throw`

If set to `true`, `Bun.build` will throw on build failure. See the section ["Logs and Errors"](#logs-and-errors) for more details on the error message structure.

In 1.2, this will default to `true`, with the previous behavior as `throw: false`

## Outputs

The `Bun.build` function returns a `Promise<BuildOutput>`, defined as:
Expand Down Expand Up @@ -1583,13 +1559,6 @@ interface BuildConfig {
*/
footer?: string;

/**
* **Experimental**
*
* Enable CSS support.
*/
experimentalCss?: boolean;

/**
* Drop function calls to matching property accesses.
*/
Expand Down
7 changes: 0 additions & 7 deletions docs/bundler/loaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,6 @@ Otherwise, the database to embed is copied into the `outdir` with a hashed filen

**HTML loader**. Default for `.html` after Bun v1.2.0.

To enable the html loader:

- For `Bun.build`: set `html: true`
- For `bun build`: `--experimental-html` CLI flag

You most likely want to use the `html` loader in conjunction with `experimentalCss: true` or `--experimental-css`.

The html loader processes HTML files and bundles any referenced assets. It will:

- Bundle and hash referenced JavaScript files (`<script src="...">`)
Expand Down
1 change: 0 additions & 1 deletion docs/runtime/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ await Bun.build({
conditions: ["react-server"],
target: "bun",
entryPoints: ["./app/foo/route.js"],
throw: true,
});
```

Expand Down
2 changes: 0 additions & 2 deletions docs/runtime/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ await Bun.build({
},
},
],
throw: true,
});
```

Expand All @@ -351,7 +350,6 @@ await Bun.build({
},
},
],
throw: true,
});
```

Expand Down
9 changes: 4 additions & 5 deletions packages/bun-inspector-frontend/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ try {
if (!Element.prototype.scrollIntoViewIfNeeded) {
Element.prototype.scrollIntoViewIfNeeded = function (centerIfNeeded) {
centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;
var parent = this.parentNode,
parentComputedStyle = window.getComputedStyle(parent, null),
parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width')),
Expand All @@ -55,15 +55,15 @@ try {
overLeft = this.offsetLeft - parent.offsetLeft < parent.scrollLeft,
overRight = (this.offsetLeft - parent.offsetLeft + this.clientWidth - parentBorderLeftWidth) > (parent.scrollLeft + parent.clientWidth),
alignWithTop = overTop && !overBottom;
if ((overTop || overBottom) && centerIfNeeded) {
parent.scrollTop = this.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + this.clientHeight / 2;
}
if ((overLeft || overRight) && centerIfNeeded) {
parent.scrollLeft = this.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + this.clientWidth / 2;
}
if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {
this.scrollIntoView(alignWithTop);
}
Expand Down Expand Up @@ -116,7 +116,6 @@ try {
entrypoints: [join(import.meta.dir, "out/manifest.js")],
outdir: "out",
minify: true,
throw: true,
});
const jsFilename = "manifest-" + jsBundle.outputs[0].hash + ".js";
// const cssBundle = await build({
Expand Down
37 changes: 4 additions & 33 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2738,31 +2738,6 @@ declare module "bun" {
*/
footer?: string;

/**
* **Experimental**
*
* Bundle CSS files.
*
* This will be enabled by default in Bun v1.2.
*
* @default false (until Bunv 1.2)
*/
experimentalCss?: boolean;

/**
* **Experimental**
*
* Bundle JavaScript & CSS files from HTML files. JavaScript & CSS files
* from non-external <script> or <link> tags will be bundled.
*
* Underneath, this works similarly to HTMLRewriter.
*
* This will be enabled by default in Bun v1.2.
*
* @default false (until Bun v1.2)
*/
html?: boolean;

/**
* Drop function calls to matching property accesses.
*/
Expand All @@ -2771,9 +2746,7 @@ declare module "bun" {
/**
* When set to `true`, the returned promise rejects with an AggregateError when a build failure happens.
* When set to `false`, the `success` property of the returned object will be `false` when a build failure happens.
*
* This defaults to `false` in Bun 1.1 and will change to `true` in Bun 1.2
* as most usage of `Bun.build` forgets to check for errors.
* This defaults to `true`.
*/
throw?: boolean;
}
Expand Down Expand Up @@ -3012,7 +2985,7 @@ declare module "bun" {
* @param {Object} config - Build configuration options
* @returns {Promise<BuildOutput>} Promise that resolves to build output containing generated artifacts and build status
* @throws {AggregateError} When build fails and config.throw is true (default in Bun 1.2+)
*
*
* @example Basic usage - Bundle a single entrypoint and check results
```ts
const result = await Bun.build({
Expand All @@ -3025,7 +2998,7 @@ declare module "bun" {
process.exit(1);
}
```
*
*
* @example Set up multiple entrypoints with code splitting enabled
```ts
await Bun.build({
Expand All @@ -3035,7 +3008,7 @@ declare module "bun" {
sourcemap: "external"
});
```
*
*
* @example Configure minification and optimization settings
```ts
await Bun.build({
Expand Down Expand Up @@ -3114,7 +3087,6 @@ declare module "bun" {
try {
const result = await Bun.build({
entrypoints: ['./src/index.tsx'],
throw: true
});
} catch (e) {
const error = e as AggregateError;
Expand Down Expand Up @@ -3152,7 +3124,6 @@ declare module "bun" {
'./src/themes/light.css'
],
outdir: './dist/css',
experimentalCss: true
});
```
@example Define compile-time constants and version information
Expand Down
12 changes: 5 additions & 7 deletions src/bake/bake.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ declare module "bun" {
// - publicPath is set by the user (TODO: add options.publicPath)
// - emitDCEAnnotations is not useful
// - banner and footer do not make sense in these multi-file builds
// - experimentalCss cannot be disabled
// - disabling external would make it exclude imported files.
// - plugins is specified in the framework object, and currently merge between client and server.

Expand Down Expand Up @@ -185,20 +184,20 @@ declare module "bun" {
* // name the user has given.
* "ClientComp",
* );
*
*
* When separateSSRGraph is disabled, the call looks like:
*
* export const ClientComp = registerClientReference(
* function () { ... original user implementation here ... },
*
*
* // The file path of the client-side file to import in the browser.
* "/_bun/d41d8cd0.js",
*
*
* // The export within the client-side file to load. This is
* // not guaranteed to match the export name the user has given.
* "ClientComp",
* );
*
*
* While subtle, the parameters in `separateSSRGraph` mode are opaque
* strings that have to be looked up in the server manifest. While when
* there isn't a separate SSR graph, the two parameters are the actual
Expand Down Expand Up @@ -526,7 +525,7 @@ declare module "bun" {
* Outside of server-components, this will be "client" when the target is
* set to "browser" and "server" otherwise.
*/
side: 'server' | 'client';
side: "server" | "client";
}
}

Expand Down Expand Up @@ -590,7 +589,6 @@ declare module "bun:bake/server" {
/** Export name */
name: string;
}

}

/** Available in client-side files. */
Expand Down
4 changes: 0 additions & 4 deletions src/bake/bake.zig
Original file line number Diff line number Diff line change
Expand Up @@ -589,15 +589,11 @@ pub const Framework = struct {
}

out.options.production = mode != .development;

out.options.tree_shaking = mode != .development;
out.options.minify_syntax = mode != .development;
out.options.minify_identifiers = mode != .development;
out.options.minify_whitespace = mode != .development;

out.options.experimental.css = true;
out.options.css_chunking = true;

out.options.framework = framework;

out.options.source_map = switch (mode) {
Expand Down
1 change: 1 addition & 0 deletions src/bake/macros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { resolve } from "node:path";
// @ts-ignore
export async function css(file: string, is_development: boolean): string {
const { success, stdout, stderr } = await Bun.spawnSync({
// TODO: remove the --experimental-css flag here once CI is upgraded to a post-#16561 bun
cmd: [process.execPath, "build", file, "--experimental-css", ...(is_development ? [] : ["--minify"])],
cwd: import.meta.dir,
stdio: ["ignore", "pipe", "pipe"],
Expand Down
30 changes: 4 additions & 26 deletions src/bun.js/api/JSBundler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,11 @@ pub const JSBundler = struct {
bytecode: bool = false,
banner: OwnedString = OwnedString.initEmpty(bun.default_allocator),
footer: OwnedString = OwnedString.initEmpty(bun.default_allocator),
experimental: Loader.Experimental = .{},
css_chunking: bool = false,
drop: bun.StringSet = bun.StringSet.init(bun.default_allocator),
has_any_on_before_parse: bool = false,
throw_on_error: bool = if (bun.FeatureFlags.breaking_changes_1_2) true else false,

env_behavior: Api.DotEnvBehavior = if (!bun.FeatureFlags.breaking_changes_1_2) .load_all else .disable,
throw_on_error: bool = true,
env_behavior: Api.DotEnvBehavior = .disable,
env_prefix: OwnedString = OwnedString.initEmpty(bun.default_allocator),

pub const List = bun.StringArrayHashMapUnmanaged(Config);
Expand Down Expand Up @@ -109,26 +107,6 @@ pub const JSBundler = struct {
did_set_target = true;
}

if (try config.getBooleanStrict(globalThis, "html")) |enable_html| {
this.experimental.html = enable_html;

if (enable_html and this.target != .browser) {
return globalThis.throwInvalidArguments("'html' is currently only supported when target is 'browser'. You can still import HTML files via the 'file' loader, just not using the 'html' loader.", .{});
}
}

if (try config.getTruthy(globalThis, "experimentalCss")) |enable_css| {
this.experimental.css = if (enable_css.isBoolean())
enable_css.toBoolean()
else if (enable_css.isObject()) true: {
if (try enable_css.getTruthy(globalThis, "chunking")) |enable_chunking| {
this.css_chunking = if (enable_chunking.isBoolean()) enable_css.toBoolean() else false;
}

break :true true;
} else false;
}

// Plugins must be resolved first as they are allowed to mutate the config JSValue
if (try config.getArray(globalThis, "plugins")) |array| {
const length = array.getLength(globalThis);
Expand Down Expand Up @@ -229,7 +207,7 @@ pub const JSBundler = struct {
}

if (try config.getTruthy(globalThis, "sourcemap")) |source_map_js| {
if (bun.FeatureFlags.breaking_changes_1_2 and config.isBoolean()) {
if (config.isBoolean()) {
if (source_map_js == .true) {
this.source_map = if (has_out_dir)
.linked
Expand Down Expand Up @@ -516,7 +494,7 @@ pub const JSBundler = struct {
};
}

if (try config.getBooleanLoose(globalThis, "throw")) |flag| {
if (try config.getBooleanStrict(globalThis, "throw")) |flag| {
this.throw_on_error = flag;
}

Expand Down
Loading

0 comments on commit af79ceb

Please sign in to comment.