Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP => feat(compiler): Add RSBuild and streamline app #14928

Open
wants to merge 2 commits into
base: damassi/feat/add-rspack
Choose a base branch
from

Conversation

damassi
Copy link
Member

@damassi damassi commented Nov 28, 2024

⚠️ Stacked on top of #14925, which works. Now the next phase.

The type of this PR is: Feat

Description

This tool is blowing my mind. Now i need to switch our entire project to rsbuild defaults which will simplify everything up and down. Wow.

@damassi damassi self-assigned this Nov 28, 2024
@artsy-peril
Copy link
Contributor

artsy-peril bot commented Nov 28, 2024

@rsbuild/plugin-react

Author: Unknown

Description: React plugin for Rsbuild

Homepage: https://github.com/web-infra-dev/rsbuild#readme

Createdabout 1 year ago
Last Updated21 days ago
LicenseMIT
Maintainers3
Releases213
Direct Dependencies@rspack/plugin-react-refresh and react-refresh
README

Rsbuild Logo

Rsbuild

The Rspack-based build tool. It's fast, out-of-the-box and extensible.

Documentation

https://rsbuild.dev/

Contributing

Please read the Contributing Guide.

License

Rsbuild is MIT licensed.

@rsbuild/plugin-node-polyfill

Author: Unknown

Description: An Rsbuild plugin to automatically inject polyfills for [Node.js builtin modules](https://nodejs.org/api/modules.html#built-in-modules) into the browser side.

Homepage: https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill#readme

Createdabout 1 year ago
Last Updatedabout 1 month ago
LicenseMIT
Maintainers3
Releases183
Direct Dependenciesassert, browserify-zlib, buffer, console-browserify, constants-browserify, crypto-browserify, domain-browser, events, https-browserify, os-browserify, path-browserify, process, punycode, querystring-es3, readable-stream, stream-browserify, stream-http, string_decoder, timers-browserify, tty-browserify, url, util and vm-browserify
README

@rsbuild/plugin-node-polyfill

An Rsbuild plugin to automatically inject polyfills for Node.js builtin modules into the browser side.

npm version license downloads

When to use

Normally, we don't need to use Node builtin modules on the browser side. However, it is possible to use some Node builtin modules when the code will run on both the Node side and the browser side, and this plugin provides browser versions of polyfills for these Node builtin modules.

By using the Node Polyfill plugin, polyfills for Node builtin modules are automatically injected into the browser-side, allowing you to use these modules on the browser side with confidence.

Usage

Install:

npm add @rsbuild/plugin-node-polyfill -D

Add plugin to your rsbuild.config.ts:

// rsbuild.config.ts
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill'

export default {
  plugins: [pluginNodePolyfill()],
}

Node Polyfills

Globals

  • Buffer
  • process

When you use the above global variables in your code, the corresponding polyfill will be automatically injected.

For instance, the following code would inject the Buffer polyfill:

const bufferData = Buffer.from('abc')

You can disable this behavior through the globals option of the plugin:

pluginNodePolyfill({
  globals: {
    Buffer: false,
    process: false,
  },
})

Modules

  • assert
  • buffer
  • console
  • constants
  • crypto
  • domain
  • events
  • http
  • https
  • os
  • path
  • punycode
  • process
  • querystring
  • stream
  • _stream_duplex
  • _stream_passthrough
  • _stream_readable
  • _stream_transform
  • _stream_writable
  • string_decoder
  • sys
  • timers
  • tty
  • url
  • util
  • vm
  • zlib

When the above module is referenced in code via import / require syntax, the corresponding polyfill will be injected.

import { Buffer } from 'buffer'

const bufferData = Buffer.from('abc')

Fallbacks

  • child_process
  • cluster
  • dgram
  • dns
  • fs
  • module
  • net
  • readline
  • repl
  • tls

Currently there is no polyfill for the above modules on the browser side, so when you import the above modules, it will automatically fallback to an empty object.

import fs from 'fs'

console.log(fs) // -> {}

Options

globals

Used to specify whether to inject polyfills for global variables.

  • Type:
type Globals = {
  process?: boolean
  Buffer?: boolean
}
  • Default:
const defaultGlobals = {
  Buffer: true,
  process: true,
}

protocolImports

Whether to polyfill Node.js builtin modules starting with node:.

  • Type: boolean
  • Default: true

For example, if you disable protocolImports, modules such as node:path, node:http, etc. will not be polyfilled.

pluginNodePolyfill({
  protocolImports: false,
})

include

Specify an array of modules for which polyfills should be injected. If this option is set, only the specified modules will be polyfilled. include is mutually exclusive with exclude.

  • Type: string[]
  • Default: undefined
pluginNodePolyfill({
  include: ['buffer', 'crypto'], // Only "buffer" and "crypto" modules will be polyfilled.
})

exclude

Specify an array of modules for which polyfills should not be injected from the default. If this option is set, the specified modules will be excluded from polyfilled. exclude is mutually exclusive with include.

  • Type: string[]
  • Default: undefined
pluginNodePolyfill({
  exclude: ['http', 'https'], // All modules except "http" and "https" will be polyfilled.
})

overrides

Override the default polyfills for specific modules.

  • Type: Record<string, string>
  • Default: {}
pluginNodePolyfill({
  overrides: {
    fs: 'memfs',
  },
})

Exported variables

  • builtinMappingResolved: A map of Node.js builtin modules to their resolved corresponding polyfills modules.
  • resolvedPolyfillToModules: A map of resolved polyfill modules to the polyfill modules before resolving.

License

MIT.

@rsbuild/core

Author: Unknown

Description: The Rspack-based build tool.

Homepage: https://rsbuild.dev

Createdabout 1 year ago
Last Updated2 days ago
LicenseMIT
Maintainers3
Releases242
Direct Dependencies@rspack/core, @rspack/lite-tapable, @swc/helpers and core-js
README

Rsbuild Logo

Rsbuild

The Rspack-based build tool. It's fast, out-of-the-box and extensible.

Documentation

https://rsbuild.dev/

Contributing

Please read the Contributing Guide.

License

Rsbuild is MIT licensed.

New dependencies added: @rsbuild/core, @rsbuild/plugin-node-polyfill and @rsbuild/plugin-react.

Generated by 🚫 dangerJS against bb19db9

Copy link

relativeci bot commented Nov 28, 2024

#1092 Bundle Size — 10.59MiB (+10.92%).

bb19db9(current) vs ffe4f84 main#484(baseline)

Important

Bundle introduced 11 and removed 8 duplicate packages – View changed duplicate packages

Warning

Bundle introduced 13 new packages: web-vitals, @sentry-internal/browser-utils, stylis and 10 more – View changed packages

Bundle metrics  Change 9 changes Regression 1 regression Improvement 3 improvements
                 Current
#1092
     Baseline
#484
Improvement  Initial JS 3.85MiB(-2.5%) 3.95MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 100% 2.04%
Change  Chunks 240(+67.83%) 143
Change  Assets 244(+67.12%) 146
Change  Modules 5465(-3.05%) 5637
Improvement  Duplicate Modules 375(-17.58%) 455
Change  Duplicate Code 4.84%(-17.69%) 5.88%
Improvement  Packages 290(-0.34%) 291
Regression  Duplicate Packages 46(+9.52%) 42
Bundle size by type  Change 2 changes Regression 2 regressions
                 Current
#1092
     Baseline
#484
Regression  JS 10.1MiB (+8.45%) 9.31MiB
Regression  Other 499.79KiB (+110.14%) 237.84KiB

Bundle analysis reportBranch damassi/add-rsbuildProject dashboard


Generated by RelativeCIDocumentationReport issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant